in reply to Extracting from output file

Howdy AllPaoTeam, welcome to the Monastery! Athanasius already pointed out that /s+/ in your code should really be /\s+/ if you intend to split on whitespace. (That's all whitespace, BTW, not just tab characters!) And as he furthermore said, a bit of sample data that shows the problem would be good: it doesn't have to be your entire file, just a portion of it that should be handled correctly but isn't.

You can also use Text::CSV to parse such files by setting the separator to a tab character, like this:

#!/usr/bin/perl use strict; use warnings; use feature qw/say/; use Text::CSV; my $csv = Text::CSV->new({ sep_char => "\t", binary => 1, # always a good idea }); while(my $row = $csv->getline(*DATA)) { say "$row->[0],$row->[1]"; } __DATA__ word1 word2 word3 word4 word5 word6

This is going to be only useful if your words are separated by precisely one tab character, though, since otherwise you'll get empty fields in between words.

Replies are listed 'Best First'.
Re^2: Extracting from output file
by AllPaoTeam (Sexton) on Aug 15, 2014 at 18:45 UTC
    I resolved it.... LOL, just being dumb, I was referencing the a non-existing variable, of course its not going to return anything. Yea I dont use strict and warnings because I dont know how to resolve what its complaining about. Thanks again for your help. -Pao

      Yea I dont use strict and warnings because I dont know how to resolve what its complaining about.

      Ah, that's even more of a reason to use them! If you get errors/warnings that you're not sure what they mean:

      • use diagnostics; to get explanations.
      • Check perldiag (these are the same ones that diagnostics prints, I think).
      • Use the Monastery's Super Search, and/or your favorite web search engine.
      • If you're still not sure, ask a new question on PM!

      You'll learn a lot this way, your Perl will improve, and your scripts will have fewer bugs/unpleasant surprises.

      There's also a book, TheDamian's Perl Best Practices, that may be of interest. It's a bit older by now, but it's got a lot of good advice.