RE: putting $1 into a var

2004-01-07 Thread Charles K. Clarkson
angie ahl <[EMAIL PROTECTED]> wrote:
: 
: I'm trying to get the value of $1 into a var, the following
: don't work and I can't figure out why
: 
: $_ = $html_body;
: my ($resrow) = m#(.*?)#;
: #print $1;
: print $resrow;
: 
: $resrow holds nothing, however if I print $1 I do have a
: match
: 
: $_ = $html_body;
: m#(.*?)#;
: my $resrow = $1;
: print $resrow;

Perhaps $html_body does not hold what you think it holds.
Commenting one line or the other seemed to work fine for me.

$_ = q|foo|;

my ($resrow) = m#(.*?)#;
print $1;
print $resrow;

__END__
Prints:
foofoo


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: putting $1 into a var

2004-01-07 Thread Rob Dixon
Angie Ahl wrote:
>
> I'm trying to get the value of $1 into a var, the following don't work
> and I can't figure out why
>
> $_ = $html_body;
> my ($resrow) = m#(.*?)#;
>m#(.*?)#;
> #print $1;
> print $resrow;
>
> $resrow holds nothing, however if I print $1 I do have a match
>
> $_ = $html_body;
> m#(.*?)#;
> my $resrow = $1;
> print $resrow;
>
> doesn't work either.
>
> How do I get $1 into a var for later use. It's driving me a little loopy
> now.
>
> I'm basically trying to extract the middle bit into a var of it's own. I
> thought that would be easy

Hi Angie.

It looks like your regex isn't matching. $1 will keep the value captured by
the last successful match.

Try this code. (The 'for ($html_body) { .. }' aliases $_ with $html_body
for the extent of the code block.)

  my $resrow;

  for ($html_body) {
if (m#(.*?)#) {
  $resrow = $1;
}
else {
  die "No match for HTML";
}
  }

  print $resrow, "\n";

So I guess you need to fix your regex. Is it possible that the actual
text contains a newline? In which case you need to replace spaces with
'\s+'.

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: putting $1 into a var

2004-01-07 Thread R. Joseph Newton
angie ahl wrote:

> hi people
>
> I'm trying to get the value of $1 into a var, the following don't work
> and I can't figure out why
>
> $_ = $html_body;
> my ($resrow) = m#(.*?)#;
> #print $1;
> print $resrow;
>
> $resrow holds nothing, however if I print $1 I do have a match

How do you know?  How are you testing to ensure that a match was found?

>
>
> $_ = $html_body;
> m#(.*?)#;
> my $resrow = $1;
> print $resrow;
>
> doesn't work either.
>
> How do I get $1 into a var for later use. It's driving me a little loopy
> now.

Just the way you show in your second example.  If a match was found, the
captured text will appear in $resrow.

Better to find out:

if (m#(.*?)#) {
   print "$1\n";
} else {
   print "Oops, back to the drawing board with this regex, huh?\n";
}

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: putting $1 into a var

2004-01-07 Thread angie ahl
Thanks to everyone who helped me with this one, I had a deadline to meet
that is now met. 

It was a missing ~ and me failing to use s on the end of my pattern

may be of use to other users but for some reason my Linux server needs
s///s; to match over newlines and my OSX set up doesn't, that didn't
help ;)

Angie

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: putting $1 into a var

2004-01-07 Thread Dan Muey

> Thanks to everyone who helped me with this one, I had a 
> deadline to meet that is now met. 
> 
> It was a missing ~ and me failing to use s on the end of my pattern
> 
> may be of use to other users but for some reason my Linux 
> server needs s///s; to match over newlines and my OSX set up 
> doesn't, that didn't help ;)

OSX! Yummy! It probably has something to do with the Unix/Mac/Winders 
newline character issue.  They all use different characters for that 
so it can cause issues.


Dmuey

> 
> Angie
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED] 
 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: putting $1 into a var

2004-01-08 Thread Jan Eden
Dan Muey wrote:

>> Thanks to everyone who helped me with this one, I had a 
>> deadline to meet that is now met. 
>> 
>> It was a missing ~ and me failing to use s on the end of my pattern
>> 
>> may be of use to other users but for some reason my Linux 
>> server needs s///s; to match over newlines and my OSX set up 
>> doesn't, that didn't help ;)
>
>OSX! Yummy! It probably has something to do with the Unix/Mac/Winders 
>newline character issue.  They all use different characters for that 
>so it can cause issues.

Well, OS X is a BSD system, so it uses UNIX newline characters. I have not experienced 
the behaviour Angie described: Perl 5.8.1 on my OS X (10.3.2) does not match newlines 
using the magical dot if the pattern modifier /s is not set.

Which environment/app did you use to test on your local OS X box?

- Jan
-- 
The day Microsoft makes something that doesn't suck is the day they start selling 
vacuum cleaners.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]