Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: filehandle regex

by JavaFan (Canon)
on Nov 16, 2010 at 20:59 UTC ( #871830=note: print w/ replies, xml ) Need Help??


in reply to filehandle regex

To print the previous line, one way of doing it is:

my $prev = ""; while (<ORA>) { print $prev if /^Func_file_permission$/; $prev = $_; }


Comment on Re: filehandle regex
Download Code
Re^2: filehandle regex
by pinnacle (Acolyte) on Nov 17, 2010 at 00:21 UTC

    Thanks for the solution it works!! One thing I don't understand why we are using my $prev = ""; also $prev = $_; due to which I am getting previous line from the file

    What's the magic behind it

    Thanks!!

      Yes, it will also work, but then the script will not run under use strict;.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      The my $prev part is there to properly declare the variable. The = "" is there to not have warnings if the first line actually matches. The ; is there to separate statements.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (19)
As of 2014-07-23 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (146 votes), past polls