Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: First attempt at bringing in file for input/output

by 1nickt (Canon)
on Oct 19, 2018 at 22:13 UTC ( [id://1224362]=note: print w/replies, xml ) Need Help??


in reply to First attempt at bringing in file for input/output

I'll also jump in and say that you can go even further than autodie (++talexb) and use a file-handling module for this stuff. It's great that you are learning the basics of opening and closing and printing to files (++), but very quickly that stuff will become boring boilerplate, and the logical computing you do between reading and writing the file will be what you'll want to focus on. Be sure to get well-grounded in the basics, but that includes becoming familiar with the basic toolkit so you can have more fun building things :-)

I recommend using Path::Tiny for file operations; it keeps things simple and easy and intuitive. For what you are doing in your test script:

#!/bin/perl use v5.14; use warnings; use Path::Tiny; my $in = $ARGV[0] or die "Usage: $0 <filename>"; path($in)->copy($in =~ s/(\.\w+)?$/.out/r); __END__
... for more realistic applications:
#!/bin/perl use v5.14; use warnings; use Path::Tiny; my $in = $ARGV[0] or die "Usage: $0 <filename>"; my $out = path($in =~ s/(\.\w+)?$/.out/r); for my $line ( path($in)->lines({ chomp => 1 }) { # do something interesting with the line $out->append("$line\n"); } __END__

Hope this helps!


The way forward always starts with a minimal test.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1224362]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-20 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found