Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: reading files in directory

by Riales (Hermit)
on Mar 20, 2012 at 00:21 UTC ( [id://960501]=note: print w/replies, xml ) Need Help??


in reply to Re^2: reading files in directory
in thread reading files in directory

Well, the first thing you'll need to do is tell Perl what the relevant files are. The simplest way to do that is to pass it in as a command-line argument. Look for @ARGV in perldoc perlvar for that.

If the files are all in the same directory and there are no other files in the directory (and you don't want to type out 25 separate filenames), you could use a loop on STDIN to receive piped into into your script:

my @filenames; push @filenames, $_ while (<STDIN>); chomp@filenames; use Data::Dumper; print Dumper(@filenames);

That way, you can get all your filenames into your script by simply doing:

ls | my_script.pl

As for actually opening each file for reading, you've already done that. What's confusing about reading the files? Have you checked perldoc -f open?

As for hashes, they're pretty simple:

my %hash; # Declare your hash. $hash{$key} = $sequence; # Assign $sequence to the hash with key $key. my $sequence_im_looking_for = $hash{$key}; # Get the sequence by looki +ng it up with its key $key.

It looks like you'll be alternating lines; line1 is the key for the sequence in line2, line3 is the key for the sequence in line4, etc.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found