Help - Search - Member List - Calendar
Full Version: Regex help
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Owen
I have a script with these three lines and it works

$line =~ s/^s*//; # Remove leading spaces
next if ($line =~ /^#/); # Skip line if it starts with #
next if ($line =~ /^s*$/); # Ship blank lines

I can replace lines 1 and 2 above with

next if($line =~ /s+|#/);

However my attempts to replace all three lines

next if($line =~ /s+|#.*$/);

gives a warning

Use of uninitialized value in concatenation (.) or string and produces return vale? of 1

for blank lines.

How can I avoid these warnings with the regexp




TIA



Owen

John W. Krahn
Owen wrote:
QUOTE
I have a script with these three lines and it works

$line =~ s/^s*//;  # Remove leading spaces

You should use s+ instead of s* because it is more efficient.

QUOTE
next if ($line =~ /^#/); # Skip line if it starts with #
next if ($line =~ /^s*$/); # Ship blank lines

You removed the whitespace two lines up so there is nothing for s to match.

QUOTE
I can replace lines 1 and 2 above with

next if($line =~ /s+|#/);

However my attempts to replace all three lines

next if($line =~ /s+|#.*$/);

gives a warning

Use of uninitialized value in concatenation (.) or string and produces return vale? of 1
for blank lines.

I don't get that warning with that regular expression so it must be something
else in your code that is causing it.

QUOTE
How can I avoid these warnings with the regexp

next if $line =~ /^s*$|^s*#/;




John
--
use Perl;
program
fulfillment


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.