Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Reg. Expression problem

by jlistf (Monk)
on Aug 02, 2000 at 20:22 UTC ( [id://25764]=note: print w/replies, xml ) Need Help??


in reply to Reg. Expression problem

perhaps you want:
use strict; use warnings; open IN, "file.txt" or die "can't open : $!\n"; while (<IN>) { # perform some tests on $_ # if its a good line, print it. } close (IN);
if you want anything more, you have to give us more details.

jeff

ps. use HTML formatting, <BR>, instead of carriage returns.

Replies are listed 'Best First'.
RE: Re: Reg. Expression problem
by Anonymous Monk on Aug 02, 2000 at 20:37 UTC
    I have a huge file that contains several lines. How do I use regular expression to match the one I want. let's say the file is like this perlmonks 1
    perlmonks(1) 2
    perlmonks(perl) 3
    'perlmonks (67) 4
    ..... ... and so on... Let's say I just want to print 1
    3
    4
    (skiping that perlmonks part I just wanted to print the numbers I want on the right side. Thankx
      allright... how about:
      while (<FILE>) { print "$1\n" if $_ =~ m/(\d+)$/ }
      this will print the last number on each line, if it is the last character on the line. for any more help, you're going to have to let us know how you decide that you want to print something.
        Thankx jeff, If I want, suppose, 32 different numbers. 1, 34 , 45, 62...and other random ones
        Do I have to write all the numbers or is there any other easier way?.......

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found