AnyDat...::File(3pm)

πŸ’– AnyDat...::File πŸ’–

okay bestie, welcome to AnyDat...::File(3pm), straight outta the User Contributed Perl Documentation ✨ grab a snack, we're doing file storage today.


✨ NAME ✨

AnyData::Storage::File β€” manipulate files with rich warnings πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

So the whole vibe here? It opens, reads from, writes to, creates and destroys files, with numerous options for error handling, flocking, binmode, etc. It's giving ✨main character file handling✨.

The simplest form is the equivalent of:

my $f    = AnyData::Storage::File->new(dirs=>\@dirs,flock=>1);
my $str1 = $f->adSlurp($file);

for( @dirs ) {
    open(IN,$file) or die $!;
}
sub slurp {
    local *IN;
    local $/ = undef;
}

But, depending on how you set the default behaviour… πŸ‘€ (and yeah, the sentence really does just end there, iconic honestly, we respect a cliffhanger πŸ’…)


🌸 SYNOPSIS 🌸

use AnyData;
my $f = AnyData::Storage::File->new;
$f->set('binmode',1|0);
$f->set('PrintError',1|0);
$f->set('RaiseError',1|0);
$f->set('Trace',1|0);
$f->set('f_dir',$dir|$dir_array)

and then the mode legend, no cap, exactly like this:

<  input, fail if doesn't exist >  output, truncate if exists, create if
doesn't >> append, create if doesn't exist +< read/write, fail if
doesn't exist

r  = < r+ =
not me staring at that last line for a full minute 😭 it's verbatim, bestie, we don't edit the lore.

πŸ’… new() πŸ’…

my $f = AnyData::Storage::File->new;

or

my $f = AnyData::Storage::File->new( %flags );

%flags is a hash which can contain any or all of:

f_dir      => $directory,   # defaults to './' (
binmode    => $binmode,     # defaults to 0 (doesn't binmode files)
printError => $warnings,    # defaults to 1 (print warning on errors)

(and yes, './' ( really is chillin' there with an unclosed paren, periodt β€” we keep it exactly how it came 🫢)


πŸŽ€ open_local_file( $fname, $mode ); πŸŽ€

Mode is one of:

  • a = append β€” open for reading & writing, create if it doesn't exist πŸ“
  • r = read β€” open for reading, fail if it doesn't exist 😭
  • u = open β€” open for reading & writing, fail if it doesn't exist πŸ’€
  • c = create β€” open for reading & writing, fail if it already exists πŸ™ˆ
  • o = overwrite β€” open for reading & writing, overwrite if it already exists πŸ”₯

Additionally, all modes fail if the file can't be opened. On systems that support flock, 'r' fails if a shared lock can not be obtained; the other modes fail if an exclusive lock can't be obtained. So like… lock your files, bestie, it's a whole boundary thing πŸ’…


and that's the whole page!! this lil gem is AnyDat...::File(3pm), perl v5.36.0, dated 2023-08-06 β€” go forth and file-manipulate responsibly, ily, bye πŸ§šπŸ’œ

πŸ“¦ where this page comes from