Click to See Complete Forum and Search --> : Perl regex Q, this should just work, right??


Kwj
03-11-2004, 06:12 PM
Hi everybody --

Thanks in advance for lending me your eyes. I must just be blind or something.

I have an input file that looks like this:


[header info]
_________

PDAILY1 [and some other stuff]
PNAME1 [etc]
PNAME2 [etc]

PDAILY2 [and some other stuff]


and I want to print every line that starts with a letter in the first column, eg the PDAILY lines. I don't want the PNAME lines because there is a space before the text starts, and I don't want blank lines either.

So here's what I have:

$line = <TMPFILE>;
while ($line = <TMPFILE>) {
if ($line eq "/\b[A-Z]/"){
system("echo $line");
}
}


I get no output. :( Would someone please recommend a solution, or a hint? I'm a total noob to regexes.

Thanks again!!

dchidelf
03-11-2004, 06:42 PM
regex: if $line starts with A-Z



if ($line =~ /^[A-Z]/){

scinerd
03-11-2004, 06:52 PM
this seems a little cleaner


#!/usr/bin/perl
open (TMPFILE, "input");
while (<TMPFILE>) {
print "$_" if /^\w/;
}
close TMPFILE;

takshaka
03-12-2004, 12:54 AM
Originally posted by scinerd
print "$_" if /^\w/;

Strictly speaking, \w will match more than Kwj says he wants (every line beginning with a letter). And that's a usless use of quotes.

print if /^[a-zA-Z]/;

Kwj
03-12-2004, 10:51 AM
Thank you soooo much for your responses! All the ways display the info I wanted, and print "$_" if /^\w/; also displays dividers ("--------------").

This is exactly what I needed. I have a lot to learn about regexes. Have a great day everybody!