[16810] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4222 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 4 18:05:38 2000

Date: Mon, 4 Sep 2000 15:05:21 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <968105120-v9-i4222@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 4 Sep 2000     Volume: 9 Number: 4222

Today's topics:
        $#- documentation bug (was: Regexp: Get the index of an nobull@mail.com
    Re: $#- documentation bug (was: Regexp: Get the index o (Mark-Jason Dominus)
    Re: $LIST_SEPARATOR bug?? (Keith Calvert Ivey)
        ANNOUNCE FreeWRL 0.26 Released (Free VRML browser for L <rcoscali@isr.ist.utl.pt>
    Re: Convert UNIX Timestamp to DateTime (Andrew J. Perrin)
    Re: Convert UNIX Timestamp to DateTime (Keith Calvert Ivey)
    Re: cookies and SSI's <elephant@squirrelgroup.com>
    Re: Date format <brondsem@my-deja.com>
    Re: fileupload issue (Maggert)
    Re: fileupload issue <andreas@happy3d.net>
    Re: Flock being stubborn (Maggert)
    Re: Flock being stubborn (Randal L. Schwartz)
    Re: Flock being stubborn (Maggert)
    Re: Flock being stubborn <bart.lateur@skynet.be>
    Re: help with forking gumbygumbygumby@my-deja.com
    Re: How do you use setuid in perl <bachelart.pierre@skynet.be>
    Re: How to make eval() secure with backtick? nobull@mail.com
    Re: How to make eval() secure with backtick? (Mark-Jason Dominus)
    Re: intranet using perl cgi (Maggert)
    Re: last/control structure problem <uri@sysarch.com>
    Re: Newbie of Regexp: How to extract the text between < <webmaster@wholefamily.com>
    Re: Newbie Questions, Gurus Help !! (Keith Calvert Ivey)
        Problem with hex->dec <ruedas@geophysik.uni-frankfurt.de>
    Re: Problem with hex->dec <tony_curtis32@yahoo.com>
    Re: Problem with hex->dec <ruedas@geophysik.uni-frankfurt.de>
    Re: Relative to Absolute help? (Peter J Scott)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 04 Sep 2000 17:44:49 +0100
From: nobull@mail.com
Subject: $#- documentation bug (was: Regexp: Get the index of an alternative matched)
Message-Id: <u98zt8yum6.fsf@wcl-l.bham.ac.uk>

"multiplexor" <abuse@localhost.com> writes:
              ^^^^^^^^^^^^^^^^^^^^

This looks like an irresponsible mung to me.  Do you have permission
from the owner of the localhost.com domain to use it in this way?
 
> ####
> $_ = 'ABCDE';
> s/(B|C|D)/
>  my $id;
>  $id = 0 if ($1 eq 'B');
>  $id = 1 if ($1 eq 'C');
>  $id = 2 if ($1 eq 'D');
> /e;
> ####
> 
> Does Perl have any function or special variable that can give me the index
> of an alternative matched?

Not prior to 5.6 and not without making each alternative a capturing
subexpression.  i.e. /(B)|(C)|(D)/.

One can use $#- to find the last matched subgroup in the last
successful match.

For details see long thread on this exact same question about two
weeks ago or read perldoc perlvar in 5.6.

Note: perldoc perlvar contains the statement "You can use $#- to
determine how many subgroups were in the last successful match."
I think this is a documentation bug resulting from cutting and pasting
the documentation of @+ into the documentation of @-.  The correct
statement is "You can use $#+ to determine how many subgroups were in
the last successful match."

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


------------------------------

Date: Mon, 04 Sep 2000 18:43:45 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: $#- documentation bug (was: Regexp: Get the index of an alternative matched)
Message-Id: <39b3ed60.1c18$1c0@news.op.net>

In article <u98zt8yum6.fsf@wcl-l.bham.ac.uk>,  <nobull@mail.com> wrote:
>> Does Perl have any function or special variable that can give me the index
>> of an alternative matched?
>
>Not prior to 5.6 and not without making each alternative a capturing
>subexpression.  i.e. /(B)|(C)|(D)/.

You can do it prior to 5.6.  For example:

        if (@matches = ($string =~ /(B)|(C)|(D)/)) {
          for ($i = 0; $i < @matches; $i++) {
            last if defined $matches[$i];
          }
          print "It matched alternative #$i.\n";
        }



------------------------------

Date: Mon, 04 Sep 2000 20:41:18 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: $LIST_SEPARATOR bug??
Message-Id: <39ce062e.93264208@news.newsguy.com>

jason <elephant@squirrelgroup.com> wrote:
>Keith Calvert Ivey <kcivey@cpcug.org> wrote ..

>look closer .. specifically the following like is removed
>
>     $$quote = 1 if $text =~ s/"/``/s;
>
>and that was the one responsible for trashing the $"

Okay, I guess, but won't your substitution still trash
paragraphs (I assume this a happening a paragraph at a time)
that contain $" twice, or contain $" and some quoted text?
Here it is again:

    while ($text =~ s/"([^"]*)"/\x93$1\x94/sg) {};

Also, I know it was in the original code, but the while() --
like the /s -- doesn't seem to serve a purpose there.  Once the
substitution has been performed, there won't be more than one "
in $text anymore, so it will never be true the second time it's
tested.

[snip]
>but after looking at the HTML output of the \x93 and \x94 .. I think I 
>prefer the simple double-quote anyway .. of course - you probably want 
>to convert those to '&quot;'s

Not necessary.  Plain " is fine except inside attribute values
(unless you quote them with single quotes, which I don't
generally do).

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


------------------------------

Date: Mon, 4 Sep 2000 17:55:12 +0100
From: Remi Cohen-Scali <rcoscali@isr.ist.utl.pt>
Subject: ANNOUNCE FreeWRL 0.26 Released (Free VRML browser for Linux)
Message-Id: <Pine.LNX.4.21.0009031825280.18714-100000@anonimo.isr.ist.utl.pt>

We are proud to annouce the very release of FreeWRL 0.26, an alpha release
of the FreeWRL free VRML browser for Linux.
This release is giving the free software community a stable enough VRML
browser to use it on a regular basis. Nevertheless, this is an alpha
release and many features are still missing.

FreeWRL features:
 - Most VRML nodes supported (MovieTexture/AudioClip and a few others Not
Yet Supp.)
 - PROTO, DEF, Inlines
 - Javascript support
 - Perlscript support
 - Java EAI interface support
 - TrueType font rendering 
 - External sensor input
 - A descent like fly mode
 - Snapshot through key/perlscripting
 - Support use as a netscape plugin (with xswallow)

Features planed for future releases:
 - Improved EAI support
 - Alpha blending
 - Mpeg1 & MovieTexture support
 - AudioClip & Sound nodes

Give it a try by viewing FreeWRL Home Page at:
 http://www.crc.ca/FreeWRL
or
 http://FreeWRL.sourceforge.net/

You can download the tarball at:
 http://www.crc.ca/FreeWRL/download/freewrl/FreeWRL-0.26.tar.gz
 ftp://ftp.rcsnet.net/pub/FreeWRL/freewrl-0.26.tar.gz
 ftp://ftp.rcsnet.net/pub/FreeWRL/freewrl-0.26.tar.bz2

You can also browse the CVS repository or directly fetch from CVS.
Look at:
 http://www.sourceforge.net/projects/freewrl

Thanks
The FreeWRL developer team



------------------------------

Date: 04 Sep 2000 12:57:51 -0400
From: aperrin@demog.berkeley.edu (Andrew J. Perrin)
Subject: Re: Convert UNIX Timestamp to DateTime
Message-Id: <uya18ksc0.fsf@demog.berkeley.edu>

jonaskuh@tell-em-off.com (Jonaskuh) writes:

> 
> That's not exactly what I want to do.. what I meant is to take a Unix
> timestamp, (i.e. 968078883) and convert it to the above date format,
> or even (Mon Sep  4 08:48:31 MDT 2000) I could still work with that..
> 
> Thanks!!

Unless I'm misunderstanding you, localtime() is what you want:

  DB<2> print scalar localtime(968078883)
Mon Sep  4 10:48:03 2000

perldoc -f localtime for more.

-- 
----------------------------------------------------------------------
Andrew Perrin - Solaris-Linux-NT-Samba-Perl-Access-Postgres Consulting
       aperrin@igc.apc.org - http://demog.berkeley.edu/~aperrin
----------------------------------------------------------------------


------------------------------

Date: Mon, 04 Sep 2000 16:55:08 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Convert UNIX Timestamp to DateTime
Message-Id: <39c6d31d.80189099@news.newsguy.com>

jonaskuh@tell-em-off.com (Jonaskuh) wrote:

>That's not exactly what I want to do.. what I meant is to take a Unix
>timestamp, (i.e. 968078883) and convert it to the above date format,
>or even (Mon Sep  4 08:48:31 MDT 2000) I could still work with that..

You'll want to use the localtime() function, either in a list
context to get an array from which you can construct the
yyyy-mm-dd hh:mm:ss string you mentioned earlier or in a scalar
context to get something like the format above.  Read about it
in perlfunc.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


------------------------------

Date: Mon, 04 Sep 2000 21:00:24 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: cookies and SSI's
Message-Id: <MPG.141eaae83ef828e4989765@localhost>

James Philip Ryan <jpryan@labs.tamu.edu> wrote ..
>jason wrote:
>
>> James Philip Ryan <jpryan@labs.tamu.edu> wrote ..
>> >"Tony L. Svanstrom" wrote:
>> >
>> >> James Ryan <jpryan@cis.tamu.edu> wrote:
>> >>
>> >> > This is my circumstance:  all of the HTML files are SHTML, and each SHT
>> >> > file runs a script via server-side-include that displays a navigation
>> >> > panel if the user is logged in.  how do I access the client's cookie da
>> >> > from a script that is run as an SSI?
>> >>
>> >> The same way that you would if it'd been a normal CGI-script.
>> >
>> >I may be doing something wrong, but when I run the script by itself (as in 
>> >an SSI directive), the $ENV{'HTTP_COOKIE'} variable contains the cookie dat
>> >When I run the script from an SSI (<!--#exec cgi=/cgi-bin/nameofscript.pl -
>> >), the variable is empty.  Any other suggestions?
>>
>> for a start .. please post *this* way round .. ie. your reply *beaneath*
>> what you're replying to .. it's just the way things are done around here
>>
>> to your problem .. do you know much about cookies ? .. you have probably
>> set the cookie to be specific to the script that it was written by (by
>> not including a PATH attribute)
>>
>> this is not really any long a Perl question .. because Tony was correct
>> - you *do* access cookies in SSI scripts *exactly* the same was as in
>> standard CGI scripts .. it's just that you need to have the PATH
>> attribute of the cookie set so that you can see it from the script that
>> you're reading it in as well as the script that it was written from
>>
>> see one of the numerous resources that cover cookies .. or even look in
>> the CGI::Cookie manual
>>
>>   perldoc CGI::Cookie
>>
>> it covers the topic reasonably well
>
>The CGI::Cookie manual said the path was being set as "/" by default; I didn't
>consider that to be the problem.  Thanks for your help...  you rock

hmm .. dunno which version that is .. but mine says that it's set to the 
full name of the script that sets the cookie by default

if the PATH was '/' then EVERY script would have access to it

  [ lines exceeding 80 chars truncated ]

-- 
  jason -- elephant@squirrelgroup.com --


------------------------------

Date: Mon, 04 Sep 2000 16:05:35 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: Date format
Message-Id: <8p0h87$4an$1@nnrp1.deja.com>

In article <8ov8ob$qqs$1@nnrp1.deja.com>,
  pularis@my-deja.com wrote:
>
>
>  What should I use on a windows machine to get a formatted date
> outpur ?. I used localtime() to get something like  Sun Sep 3 23:58:20
> 2000 . What I need has to be of the
> 09_03_00 format. I dont need the time , just the date. thx
>

I use:

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =  localtime
(time);
my $ap = "AM";
if ($hour == 12)
	{$ap = "PM";}
elsif ($hour == 0)
	{$hour = $hour + 12;}
elsif ($hour > 12)
	{$ap = "PM";$hour = ($hour-12);}
if (length($min) == 1)
	{$min = "0".$min;}
$mon=$mon+1;
$year=$year+1900;
my $time = $hour.":".$min.$ap." ".$mon."/".$mday."/".$year;



As you can see, this is more than what you need, but the first line
will help you.  It extracts all the parts of the time.

--
Dave Brondsema


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 04 Sep 2000 16:28:06 GMT
From: mag@ionet.net (Maggert)
Subject: Re: fileupload issue
Message-Id: <39b3cd82.836755861@news.ionet.net>

On Sun, 3 Sep 2000 23:10:47 +0200, "Shagma" <andreas@happy3d.net>
wrote:

>I am using input type=file in a form for a upload script.
>It works fine, but I alså want the filename.

$file =~ s/.*\\([^\\]+)$/$1/;


MP


------------------------------

Date: Mon, 4 Sep 2000 23:31:12 +0200
From: "Shagma" <andreas@happy3d.net>
Subject: Re: fileupload issue
Message-Id: <pAUs5.4667$Yi4.94196@news1.online.no>

> $file =~ s/.*\\([^\\]+)$/$1/;

Hey!
Thankyou.
It works, at least at the PC platform.

If you ever come to Oslo, the beer is on me.

I also want to thanx the other people in the group who have resonded to my
question.
:))




------------------------------

Date: Mon, 04 Sep 2000 17:43:15 GMT
From: mag@ionet.net (Maggert)
Subject: Re: Flock being stubborn
Message-Id: <39b3de49.841050046@news.ionet.net>

On Mon, 4 Sep 2000 16:23:26 +0200, "Lincoln Marr"
<lincolnmarr@nospam.europem01.nt.com> wrote:

>I posted a while back about a problem I was having with flock - I couldn't
>get it to work. I've since read all your advice and written a test script,
>which theoretically should lock the file perfectly (isn't theory
>wonderful??).
>
	I just use this;

sub lock {
my $filehandle = $_[0];
use Fcntl qw(:flock);
        flock($filehandle,LOCK_EX) if ($^O ne 'NT' && $^O ne
'MSWin32');
        seek($filehandle, 0, 2);
	    }

	Call it with your filehandle. &lock("FILE");


MP


------------------------------

Date: 04 Sep 2000 11:31:55 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Flock being stubborn
Message-Id: <m1g0nguhyc.fsf@halfdome.holdit.com>

>>>>> "Maggert" == Maggert  <mag@ionet.net> writes:

Maggert> use Fcntl qw(:flock);
Maggert>         flock($filehandle,LOCK_EX) if ($^O ne 'NT' && $^O ne
Maggert> 'MSWin32');

There's no point in that O/S test.  If it doesn't exist, then this
code won't even compile.  Way too late to check at runtime.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: Mon, 04 Sep 2000 19:34:10 GMT
From: mag@ionet.net (Maggert)
Subject: Re: Flock being stubborn
Message-Id: <39b3f812.847651688@news.ionet.net>

On 04 Sep 2000 11:31:55 -0700, merlyn@stonehenge.com (Randal L.
Schwartz) wrote:

>>>>>> "Maggert" == Maggert  <mag@ionet.net> writes:
>
>Maggert> use Fcntl qw(:flock);
>Maggert>         flock($filehandle,LOCK_EX) if ($^O ne 'NT' && $^O ne
>Maggert> 'MSWin32');
>
>There's no point in that O/S test.  If it doesn't exist, then this
>code won't even compile.  Way too late to check at runtime.
>
	I've had NT return errors because it couldn't use flock. I put
this code in and NT doesn't complain anymore. Before, scripts running
on NT died. Thats not to say it right though, but it does prevent
scripts running on NT from dying. Of course I haven't done anything to
lock the file on NT either.<G>


MP


------------------------------

Date: Mon, 04 Sep 2000 21:48:24 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Flock being stubborn
Message-Id: <i468rsclft4f5uam0pd36ehgojh930q6pn@4ax.com>

Randal L. Schwartz wrote:

>Maggert> use Fcntl qw(:flock);
>Maggert>         flock($filehandle,LOCK_EX) if ($^O ne 'NT' && $^O ne
>Maggert> 'MSWin32');
>
>There's no point in that O/S test.  If it doesn't exist, then this
>code won't even compile.  Way too late to check at runtime.

Oh it exists. It compiles. Only, it gives a runtime error.

-- 
	Bart.


------------------------------

Date: Mon, 04 Sep 2000 15:38:44 GMT
From: gumbygumbygumby@my-deja.com
Subject: Re: help with forking
Message-Id: <8p0fm2$2gl$1@nnrp1.deja.com>


> So can I just have the child process call the sub &getdata; while the
> parent process just waits for all of the children to finish before
> moving on?
no, since it will be two processes running you have to open pipes to
communicate between the mother/childs,


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 4 Sep 2000 17:33:21 +0200
From: "tuple" <bachelart.pierre@skynet.be>
Subject: Re: How do you use setuid in perl
Message-Id: <8p0fap$v7d$1@news1.skynet.be>

Why don't you use a C wrapper ?
Perl programming 2edition page 360 last 3 lines.

Hope it helps.
Pierre Bachelart.



<shobs11@my-deja.com> wrote in message news:8oob50$gko$1@nnrp1.deja.com...
> I am trying to run a script, but the user who is to run the script
> needs root permissions to do what the script is to do.
> setuid should do it, and I can get this working in C/C++ but I would
> like to use it within perl.
> Can anyone tell me how to do this?
> Are there any security problems with using setuid with perl?
>
> Thankyou in advance.
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.




------------------------------

Date: 04 Sep 2000 17:46:23 +0100
From: nobull@mail.com
Subject: Re: How to make eval() secure with backtick?
Message-Id: <u966ocyujk.fsf@wcl-l.bham.ac.uk>

rocky@panix.com (R. Bernstein) writes:

> Let's say I have a program where I read in from a secure source a
> command, $cmd, which may refer to a variable name, $var. (Below the
> command is 'echo $var'.) And let's say from an insecure source I can
> set $var.

You are getting confused about what your question really is.  All this
stuff about $cmd and the extra level of eval() indirection is
irrelevant to your real question since $cmd is from a trusted source.

Your question simplifies to:

   #!/bin/perl
   $var=<>;
   # How can I make $var safe?
   print `echo $var`;

> I simple-minded approach is to replace escape backticks which might
> be in $var. But is this complete? 

No you must also avoid $() constructs, semicolons, >() constructs <()
constructs, | and just about any other shell metacharacter.

The answer is probably to do:

   print `echo \Q$var`;

Note this also prevents the shell doing word-splitting, substitution
or globbing on the value that is interpolated by $var.  If this is not
what you want then you'll have to be more precise about exactly what
semantics you want.   

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


------------------------------

Date: Mon, 04 Sep 2000 19:11:59 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: How to make eval() secure with backtick?
Message-Id: <39b3f3fe.1cdc$37@news.op.net>

[mailed and posted]

In article <wihaedorgib.fsf@panix3.panix.com>,
R. Bernstein <rocky@panix.com> wrote:
>  #!/bin/perl
>  $cmd='echo $var';  # Could be read in from a file
>  $var=<>;
>  ##$var =~ s/`/\\`/g;
>  $cmd = eval qq/"$cmd"/;
>  print `$cmd`;


I suggest that you use the cookbook recipe here.  

It seems to me that the only reason you are doing 'eval' is to
substitute the string '$var' in $cmd with the value of $var.  Since
that's the case, I suggest you replace the 'eval' with something a
little more predictable:

  # Perl Cookbook, chapter 19
  die "cannot fork: $!" unless defined ($pid = open(SAFE_KID, "|-"));
  if ($pid == 0) {
      my @command_words = split /\s+/, $cmd;  ## MJD
      for (@command_words) {                  ## MJD
        $_ = $var if $_ eq '$var';            ## MJD
      }                                       ## MJD
      exec(@command_words) or die "can't exec @command_words: $!";
  } else {
      @output = <SAFE_KID>;
      close SAFE_KID;                 # $? contains status
  }


Since what you really want is to replace $var with its value in the
command, that is exactly what I've done.  After I break up $cmd into
words, I look through the words, and when I find one that looks like
'$var', I replace it with the value of $var.

Since the shell isn't involved here, we don't have to worry that $var
might contain special shell characters.





------------------------------

Date: Mon, 04 Sep 2000 16:23:27 GMT
From: mag@ionet.net (Maggert)
Subject: Re: intranet using perl cgi
Message-Id: <39b3cc51.836450191@news.ionet.net>

On Mon, 04 Sep 2000 11:07:36 GMT, richard_dobson@my-deja.com wrote:

>Please could someone give me some ideas? I have to come up with some
>good ideas for a research companies intranet. They would like it to
>become a vital information resource for the workers, and an invaluable
>forum for information interchange. All I can think of really is using
>a bulletin board or chatgroup/newsgroup kind of setup.
>Are there any perl cgi scripts around for this, or does anyone have any
>impressive ideas for an intranet, using perl maybe?
>
	Smartworker! smartworker.org 
Not a trivial program!


MP


------------------------------

Date: Mon, 04 Sep 2000 20:28:58 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: last/control structure problem
Message-Id: <x71yyzoq9g.fsf@home.sysarch.com>

>>>>> "SK" == Stephen Kloder <stephenk@cc.gatech.edu> writes:

  SK> Replace lines 11-15 with:

  SK>     $file = $switching_customers;
  SK>     foreach (@line) {
  SK>            @fields = split /\|/;
  SK>            next unless ($fields[0] eq $key);
  SK>            $file = $ion_customers;
  SK>            last;
  SK>     } #end of foreach


and why the loop if all you are checking is the first line?

	if ( (split /\|/, $line[0])[0] eq $key ) {

		$file = $ion_customers;
	}

and that split could be replaced by a regex:

	if ( $line[0] =~ /^$key\|/ ) {

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


------------------------------

Date: Mon, 4 Sep 2000 20:03:26 +0200
From: "Shimon Bollinger" <webmaster@wholefamily.com>
Subject: Re: Newbie of Regexp: How to extract the text between <body> and </body>?
Message-Id: <39b3d623$1@news.barak.net.il>

> >>As title, I originally think that it is very simple, like:
> >>
> >>$text = <web page text>;
> >>$text = /<body>(.*?)<\/body>/img
> >>
> >>but turn out it not work, seen to me that it is the problem of
> >>multi-line, so I change to
> >
> >you're correct - the above regex doesn't do what you want because of the
> >multi-line thing
>
> hee hee .. AND because you're using an assignment operator so the search
> is being done on the contents of $_ which is probably not what you want
[...]

PLUS...
1) in scalar context, RE's return true or false, not the matches;
2) you don't want to use the global (/g) modifier
3) the <body> tag can contain attributes (e.g. <body bgcolor="#000000">)




------------------------------

Date: Mon, 04 Sep 2000 19:00:55 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Newbie Questions, Gurus Help !!
Message-Id: <39c8ef9d.87486802@news.newsguy.com>

reg_exp@my-deja.com wrote:

>while ($workunit =~ m/thisandthat/gs) {
>...
>... code to modify $workunit here
>...
>}
>
>the problem of course is that once the $workunit gets modified, the
>position of the match is reset to the beginning - how can i modify the
>regular expression within the loop as well as find all occurences of
>the pattern ? can i use the pos function for this ??

If you're modifying the "thisandthat" part of $workunit, you
might be better off doing the modification in the second part of
a substitution:

    $workunit =~ s{(thisandthat)}
        {
            my $text = $1;
            # modify $text as desired
            $text;
        }gse;

Note that the /s modifier is only meaningful if the
"thisandthat" pattern contains the . metacharacter.

Also, you'll likely get more and better answers if you post with
a subject line that actually indicates the subject of your
question, and don't include unrelated questions in the same
message.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


------------------------------

Date: Mon, 04 Sep 2000 19:43:38 +0200
From: Thomas Ruedas <ruedas@geophysik.uni-frankfurt.de>
Subject: Problem with hex->dec
Message-Id: <39B3DF4A.2AFE7387@geophysik.uni-frankfurt.de>

Can somebody explain me how the hex function works? I can't even
reproduce the example from the documentation, which says:
    print hex '0xAf'; # prints '175'
    print hex 'aF';   # same
On my machine, I get
perl -e 'print hex '0xAf'; print "\n"'
373
perl -e 'print hex 'af'; print "\n"'
175

I also tried
perl -e 'print hex '2A'; print "\n"'
Bareword found where operator expected at -e line 1, near "2A"
        (Missing operator before A?)
syntax error at -e line 1, near "2A"
OTOH,
perl -e 'print hex '0x2A'; print "\n"'
66
is wrong.

So, how would I have got a correct decimal value from the 2 above
examples?
-- 
------------------------------------------------------------------------
Thomas Ruedas
Institute of Meteorology and Geophysics, J.W.Goethe University Frankfurt
e-mail: ruedas@geophysik.uni-frankfurt.de
http://www.geophysik.uni-frankfurt.de/~ruedas/
------------------------------------------------------------------------


------------------------------

Date: 04 Sep 2000 12:56:59 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Problem with hex->dec
Message-Id: <87k8cskplg.fsf@limey.hpcc.uh.edu>

>> On Mon, 04 Sep 2000 19:43:38 +0200,
>> Thomas Ruedas <ruedas@geophysik.uni-frankfurt.de> said:

> Can somebody explain me how the hex function works? I can't even
> reproduce the example from the documentation, which says:
>     print hex '0xAf'; # prints '175'
>     print hex 'aF';   # same
> On my machine, I get
> perl -e 'print hex '0xAf'; print "\n"'
          <---------->    <------------>

You've got single quotes confusing things in the shell.

Try:

    perl -e "print hex '0xAf'"     # \n to taste

hth
t
-- 
"I'm not easily impressed.  Wow!  A blue car!"
                                               Homer Simpson


------------------------------

Date: Mon, 04 Sep 2000 20:46:23 +0200
From: Thomas Ruedas <ruedas@geophysik.uni-frankfurt.de>
Subject: Re: Problem with hex->dec
Message-Id: <39B3EDFF.3D1D8B04@geophysik.uni-frankfurt.de>

>> On my machine, I get
>> perl -e 'print hex '0xAf'; print "\n"'
>          <---------->    <------------>
>You've got single quotes confusing things in the shell.
>Try:
>    perl -e "print hex '0xAf'"     # \n to taste
Thanks, seems that this was the point.
-- 
------------------------------------------------------------------------
Thomas Ruedas
Institute of Meteorology and Geophysics, J.W.Goethe University Frankfurt
e-mail: ruedas@geophysik.uni-frankfurt.de
http://www.geophysik.uni-frankfurt.de/~ruedas/
------------------------------------------------------------------------


------------------------------

Date: Mon, 04 Sep 2000 16:05:58 GMT
From: peter@PSDT.com (Peter J Scott)
Subject: Re: Relative to Absolute help?
Message-Id: <GLPs5.2643$x6.117296@news1.gvcl1.bc.home.com>

In article <8oua6i$sai$1@nnrp1.deja.com>,
 ptomsic@my-deja.com writes:
>Does anyone know of anything currently avail that will transform
>relative links to absolute?
>
>I've got a full directory listing of 2400 html files, and I'm searching
>for something that will allow me to supply the root directory, and the
>URL, and have it transform (inside the HTML files)
>a link such as (href=../../file.html) to
>(http://sitename.com/dir1/dir2/file.html)

Something like the following strategy should work:

For each file, create a HTML::TreeBuilder and parse the file.
Call traverse on the top level element and create a callback that looks for
tags with link attributes.  Steal the list from LinkExtor.
Change the URL with the URI::URL::abs method, passing your base URL.
Call the as_HTML method on the top-level element and print it to the new file.

-- 
Peter Scott


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4222
**************************************


home help back first fref pref prev next nref lref last post