Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^5: reading files to different output files.

by marinersk (Priest)
on May 28, 2017 at 14:05 UTC ( [id://1191432]=note: print w/replies, xml ) Need Help??


in reply to Re^4: reading files to different output files.
in thread reading files to different output files.

Do I have to somehow open the input files in the script?

Yes.

open my $input_file, '<', $input_filename or die "Cannot open input fi +le $input_filename: $!.\n"; while (my $input_line = <$input_file>) { chomp $input_line; print "[$input_line]\n"; } close $input_file;

Replies are listed 'Best First'.
Re^6: reading files to different output files.
by ic23oluk (Sexton) on May 28, 2017 at 15:11 UTC
    the input file should come from the command line. i don't want to determine the file within the script. Doesn't <> within the while loop open the files the users enters in the command line? If not, how can i implement the open command in my script?
      Doesn't <> within the while loop open the files the users enters in the command line?

      Yes, and there's more to it. Read about the null filehandle in I/O Operators, there's much to learn about @ARGV, $ARGV and ARGV, all three being "magical".

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

      shmem's guidance is spot on, as usual. Be careful about command line filenames with wildcards, as these are handled differently in Windows vs. Linux.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 04:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found