SA-MP Forums Archive
If string equals regex (Perl) - Need Quick help. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Other (https://sampforum.blast.hk/forumdisplay.php?fid=7)
+--- Forum: Everything and Nothing (https://sampforum.blast.hk/forumdisplay.php?fid=23)
+--- Thread: If string equals regex (Perl) - Need Quick help. (/showthread.php?tid=429594)



If string equals regex (Perl) - Need Quick help. - RanSEE - 10.04.2013

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.


Re: If string equals regex (Perl) - Need Quick help. - iJumbo - 10.04.2013

Have you tried without $ ($ means end of string)


Re: If string equals regex (Perl) - Need Quick help. - SchurmanCQC - 10.04.2013

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


Re: If string equals regex (Perl) - Need Quick help. - RanSEE - 11.04.2013

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


Re: If string equals regex (Perl) - Need Quick help. - iJumbo - 11.04.2013

Ok so that correct?


Re: If string equals regex (Perl) - Need Quick help. - FunnyBear - 11.04.2013

Its right now


Re: If string equals regex (Perl) - Need Quick help. - RanSEE - 11.04.2013

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