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

Re: read files into 2D arrays and print element?

by haukex (Archbishop)
on Nov 29, 2016 at 17:08 UTC ( [id://1176833]=note: print w/replies, xml ) Need Help??


in reply to read files into 2D arrays and print element?

Hi fasoli,

BrowserUk and LanX already gave you some solutions, I just had a few other suggestions for your code:

Note that you write /${molec}-times-(\d+)-clust(\d{1})/;, but then you don't check whether the match succeeded (e.g. /.../ or die "Didn't match filename $_";), if it didn't then the variables $1, $2 etc. won't be updated! Try printing out the filename "$path\/${molec}-times-${times}-clust${cluster}.out" to ensure that you're generating the correct filename (probably easiest to store the filename in a variable first).

A few more: use glob instead of `ls ...`, and only declare your variables in the scope where they're actually needed, otherwise they're hardly any better than globals (open my $input, ..., while (my $line = <$input>), etc.).

Hope this helps,
-- Hauke D

Replies are listed 'Best First'.
Re^2: read files into 2D arrays and print element?
by fasoli (Beadle) on Nov 29, 2016 at 17:15 UTC

    Oh good point, I normally do put in an if clause to check for the matching, I forgot. But yes I did print the path and the filenames first. Thanks for picking it up! :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-24 04:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found