in reply to Re^3: Extract the variable
in thread Extract the variable

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^5: Extract the variable
by johngg (Canon) on Jun 26, 2007 at 09:50 UTC
    I would be interested to know why you feel you have to use IO::File. Is it perhaps mandated by your employers? Here is the script amended to use IO::File;. Only three lines have changed and I have left the original lines in comments. You should have been able to work this out from the documentation for yourself.

    use strict; use warnings; use IO::File; my $inFile = q{spw623147.txt}; my $inFH = IO::File->new($inFile, O_RDONLY) #open my $inFH, q{<}, $inFile or die qq{open: $inFile: $!\n}; while ( $_ = $inFH->getline() ) #while ( <$inFH> ) { if ( m{\A\.rem} ) { print qq{ Comment Line: $_}; next; } if ( m{\A\.declare\s+(\S+)} ) { print qq{ Data Line: $_}; print qq{ Variable is: $1\n}; next; } print qq{Not recognised: $_}; } $inFH->close() #close $inFH or die qq{close: $inFile: $!\n};

    Cheers,

    JohnGG

Re^5: Extract the variable
by chromatic (Archbishop) on Jun 26, 2007 at 05:52 UTC

    Per the documentation of IO::File, you call the open() method on the IO::File object instead of using open directly. Which part of that is giving you trouble? What output do you receive?

Re^5: Extract the variable
by blazar (Canon) on Jun 26, 2007 at 09:01 UTC
    Hi John, Thanx for the solution ... Please tell me how to use IO::File module instead of open function in this scenario.

    Actually, it's the other way round: you are using IO::File (BTW: to render this link in the source of your node you can use [mod://IO::File]) and he suggested you to use a plain regular open. If you actually read (did you?) his post, you'll notice he gives you and explicit example about how to do so, namely:

    my $inFile = q{spw623147.txt}; open my $inFH, q{<}, $inFile or die qq{open: $inFile: $!\n};

    So, what's wrong with that?!?

    BTW: if you are confused by the alternate delimiters, the use of which in this context may be exaggerate and controversial to some, that can be:

    my $inFile = 'spw623147.txt'; open my $inFH, '<', $inFile or die "open: $inFile: $!\n";