If string equals regex (Perl) - Need Quick help.
#1

I’m trying to use regular expression to match return text from SQL Plus,

Код:
ITEM   COST
-----  ------
SHOES  $10.99	
COAT   $24.95
I want to skip the ITEM line and also the hyphen line. The number of hyphens will vary depending on the values returned by the SQL script.

I can break the lines into words with:

Код:
my @wordsOnLine = split (/\s+/, $line);
This test works fine for skipping the ITEM line

Код:
if ($wordsOnLine[0] eq "ITEM") {next;}
But I want to use regular expressions so I can match the hypen line of any length. These are the lines I used, and neither one of the if statements work to skip the lines:

Код:
if ($wordsOnLine[0] =~ "/^ITEM$/") {next;}
if ($wordsOnLine[0] =~ "/^-+$/") {next;}
How do I write a perl if statement to completely match a regular expression?

I Am new at perl, so please bear me.
Reply
#2

Have you tried without $ ($ means end of string)
Reply
#3

Yes... I believe that '$' is the end of line/string character.
Reply
#4

Thank you!
Figured,
Код:
next if $line =~ /^ITEM/ or $line =~ /^[-\s]+$/;
I didnt need to split that line as well
Reply
#5

Ok so that correct?
Reply
#6

Its right now
Reply
#7

Quote:
Originally Posted by iJumbo
Посмотреть сообщение
Ok so that correct?
Yes it is, thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)