in reply to Re: Using a Hash Variable in an If Statement
in thread Using a Hash Variable in an If Statement

I apologize for the many questions, but what does the  print "$_\n" for @{ $data{$name} }; do? Is this just saying that I want to print a new line for each piece of data within each $name? Thanks.

Replies are listed 'Best First'.
Re^3: Using a Hash Variable in an If Statement
by edimusrex (Monk) on May 11, 2015 at 21:00 UTC
    it means print each value for the hash referenced at $data{$name} (which would look like this in a data dump (data{APRL} => 7.1963). $_ is a special variable which references the current element. This is the same thing

    foreach my $line (@{$data{$name}}) { #do something }


    Where $line is the same thing as $_, more than 1 way to skin a cat. So it's say print out the hash value of the specified key and also print a new line with it so everything won't be bunched up on a single line. Hope that makes sense.
      OK that makes a lot of sense. One final question. Do you have an idea about how to print each each number (and its respective times) to a different column, using sprintf? Ideally I'd like to read these values into Matlab, and if I could create a column separating each number (1,2...15) with each time, that would save time rather than using Excel. Thanks for all of your help.

        One final question. Do you have an idea about how to print each each number (and its respective times) to a different column, using sprintf?

        You can use the documentation that comes with your perl installation like so: perldoc -f sprintf from your CLI and read all about it.
        Try out what you have read and if you are still having problems with it, post such.
        The answer you seek is just right on your keyboard. :)

        If you tell me, I'll forget.
        If you show me, I'll remember.
        if you involve me, I'll understand.
        --- Author unknown to me
        If you wanted to print to a csv file it can be done easily. Basically redirect all print statements to output

        Example :
        open my $out, ">", "rat.csv" or die "Can't write file:$!"; for my $name (@names) { print $out "$name,"; for (@{$data{$name}}) { print $out "$_,"; } print $out "\n"; $i++; } close($out);


        That should give you a nice CSV which would open nicely in any text editor but more importantly Excel