[17839] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5259 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 5 09:05:34 2001

Date: Fri, 5 Jan 2001 06:05:15 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <978703515-v9-i5259@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 5 Jan 2001     Volume: 9 Number: 5259

Today's topics:
    Re: $ENV{'QUERY_STRING'} Question <iltzu@sci.invalid>
        $Values in a DBM larger than 1024 Bytes ... <bernhard.voss@materna.de>
    Re: $Values in a DBM larger than 1024 Bytes ... (Martien Verbruggen)
    Re: $Values in a DBM larger than 1024 Bytes ... (Garry Williams)
    Re: [Q] matching many regular expressions [..] (Anno Siegel)
    Re: [Q] matching many regular expressions [..] <ian.trudel@tr.cgocable.ca>
    Re: [Q] matching many regular expressions [..] (Anno Siegel)
    Re: [Q] matching many regular expressions [..] <ian.trudel@tr.cgocable.ca>
    Re: [Q] matching many regular expressions [..] <ian.trudel@tr.cgocable.ca>
    Re: [Q] matching many regular expressions [..] (Anno Siegel)
    Re: advice (Peter L. Berghold)
    Re: beginner question (Brandon Metcalf)
    Re: check this script (Garry Williams)
    Re: Controlling a serial port (Bbirthisel)
        evaluating character-literals <fd@orga.com>
    Re: evaluating character-literals (Martien Verbruggen)
    Re: evaluating character-literals (Mark Jason Dominus)
    Re: evaluating character-literals (Martien Verbruggen)
    Re: evaluating character-literals (Mark Jason Dominus)
    Re: FAQ 7.9:   How do I create a module? (Anno Siegel)
        Getting IP address <aobrien@student.usyd.edu.au>
    Re: Getting IP address (Martien Verbruggen)
    Re: gid.. host file <Per-fredrik.Pollnow@epk.ericsson.se>
    Re: gid.. host file (Martien Verbruggen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 5 Jan 2001 11:16:33 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: $ENV{'QUERY_STRING'} Question
Message-Id: <978692214.16506@itz.pp.sci.fi>

In article <slrn95a7nu.edk.mgjv@martien.heliotrope.home>, Martien Verbruggen wrote:
>On 4 Jan 2001 10:42:15 GMT,
>	Ilmari Karonen <iltzu@sci.invalid> wrote:
>>>On 3 Jan 2001 13:09:59 GMT,
>>>	Ilmari Karonen <iltzu@sci.invalid> wrote:
>>>> 
>>>>   $q =~ s/[^ \w]/sprintf '%%%02X', ord $&/eg;
>>>>   $q =~ tr/ /+/;
>>>
 [snip]
>> 
>>   $query =~ tr/+/ /;
>>   $query =~ s/%([\dA-F][\dA-F])/chr hex $1/ieg;
>> 
 [snip]
>
>That's not the point. The point is that any escape sequence is allowed
>to be used in a query string, regardless of whether it's reserved or
>not. If I decide to escape the hypen, or _, or ~, then your CGI program
>_should_ correctly deal with it. if you only implement partial decoding,
>then you won't do everything correctly.

Um, if that's your point then obviously we agree.  I just don't see
why you brought it up, since the two-liners I posted are both fully
RFC 2396 compliant, nothing "partial" about it.  (They do assume ISO
8859-1 character encoding and no locale.)  Did you actually read them?


>And please note that the stuff you have above is substantially different
>from the original solution I commented on. Of course, if we keep going

Okay, fair enough.  I jumped to this thread in the middle, and have no
idea what kind of missolution the OP may have had.  If you were still
addressing that, I can see why we've been talking past each other.


>or two characters, or even a whole swag of them. If you don't _know_ all
>of the possibilities, you should use a module, instead of partially
>implementing stuff.

I think that's what I said when I joined this thread.

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post
 something, we discuss its implications.  If the discussion happens to
 answer a question you've asked, that's incidental." -- nobull in clpm






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

Date: Fri, 05 Jan 2001 13:49:29 +0100
From: Bernhard =?iso-8859-1?Q?Vo=DF?= <bernhard.voss@materna.de>
Subject: $Values in a DBM larger than 1024 Bytes ...
Message-Id: <3A55C2D9.17894C7@materna.de>

Hi everyone,

is it possible to set a value to a key in a hash / Perl DB , with a
"length()" greater than 1024 Bytes ?

Example:

dbmopen(%DB,"afile",0660);
foreach $key (sort(keys %DB))
{

     if  ($key eq "this_is_the_key")
     {
          $DB{$key}="here should be a long long string with a length
greater then 1024 Characters    " ;
     }

}
dbmclose %DB;


When stringlen is above 1024 bytes, this will cause an error.
I need length up to 10000 Chars ....

Any idea ??

regards,

          bernhard voss



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

Date: Sat, 6 Jan 2001 00:34:06 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: $Values in a DBM larger than 1024 Bytes ...
Message-Id: <slrn95bjae.suo.mgjv@martien.heliotrope.home>

On Fri, 05 Jan 2001 13:49:29 +0100,
	Bernhard Voß <bernhard.voss@materna.de> wrote:
> Hi everyone,
> 
> is it possible to set a value to a key in a hash / Perl DB , with a
> "length()" greater than 1024 Bytes ?

Use a dbm library that supports larger lengths.

Read the manual page of DB_File (with man, or perldoc, or as HTML,
whatever is installed on your system), and maybe the manual pages of the
db libraries installed on your system.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In the fight between you and the
Commercial Dynamics Pty. Ltd.   | world, back the world - Franz Kafka
NSW, Australia                  | 


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

Date: Fri, 05 Jan 2001 13:52:13 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: $Values in a DBM larger than 1024 Bytes ...
Message-Id: <hkk56.12$yI4.1248@eagle.america.net>

On Fri, 05 Jan 2001 13:49:29 +0100, Bernhard Voß
<bernhard.voss@materna.de> wrote:

>is it possible to set a value to a key in a hash / Perl DB , with a
>"length()" greater than 1024 Bytes ?

No, if you mean NDBM_File when you say "Perl DB".  

>Example:
>
>dbmopen(%DB,"afile",0660);

This function has been deprecated in favor of tie() for years.  Use
tie() instead.  See tie section of perlfunc.  

>When stringlen is above 1024 bytes, this will cause an error.
>I need length up to 10000 Chars ....
>
>Any idea ??

Yes.  Use DB_File.  It has no practical limit on the size of either
its keys values.  

-- 
Garry Williams


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

Date: 5 Jan 2001 11:14:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: [Q] matching many regular expressions [..]
Message-Id: <934ab9$pbc$3@mamenchi.zrz.TU-Berlin.DE>

Ian Trudel <ian.trudel@tr.cgocable.ca> wrote in comp.lang.perl.misc:
>Hello,
>
>   I'm willing to match many regular expressions at once, see reference [1].
>However, I would like to do so _with constrains_. For example (simple one),
>if I want to match two pair of numbers, separated by a coma and that has two
>digits, and each has a constrains. The first one has, let's say, to be
>between 0 and 40 and the second has to be between 41 and 50. I'd like to be
>able to work as following (or similarly):
>
>$result = manyReg{
>   /([0-9]{2})/ && ($1 <= 40),
>   /([0-9]{2})/ && ($1 > 40 && $1 <= 50)
>};

Determining numeric ranges is not what regexes are best at.  Except
for extremely simple cases things get messy very soon.  It's usually
better to catch the numeric value(s) in $1 and friends and do a
separate check.  Whether or not this can be combined with the
techniques described in your reference (which I snipped) will depend
on your data and your ability to creatively modify the examples.

My advice is to go with a potentially slow but correct solution as
sketched in your code above.  Optimize it only if it turns out
to be a bottleneck.

Anno


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

Date: Fri, 05 Jan 2001 12:27:33 GMT
From: "Ian Trudel" <ian.trudel@tr.cgocable.ca>
Subject: Re: [Q] matching many regular expressions [..]
Message-Id: <V4j56.1236$Br2.123104@carnaval.risq.qc.ca>

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> a écrit dans le message
news: 934ab9$pbc$3@mamenchi.zrz.TU-Berlin.DE...
> Ian Trudel <ian.trudel@tr.cgocable.ca> wrote in comp.lang.perl.misc:
> >Hello,
> >
> >   I'm willing to match many regular expressions at once, see reference
[1].
> >However, I would like to do so _with constrains_. For example (simple
one),
> >if I want to match two pair of numbers, separated by a coma and that has
two
> >digits, and each has a constrains. The first one has, let's say, to be
> >between 0 and 40 and the second has to be between 41 and 50. I'd like to
be
> >able to work as following (or similarly):
> >
> >$result = manyReg{
> >   /([0-9]{2})/ && ($1 <= 40),
> >   /([0-9]{2})/ && ($1 > 40 && $1 <= 50)
> >};
>
> Determining numeric ranges is not what regexes are best at.  Except
> for extremely simple cases things get messy very soon.  It's usually
> better to catch the numeric value(s) in $1 and friends and do a
> separate check.  Whether or not this can be combined with the
> techniques described in your reference (which I snipped) will depend
> on your data and your ability to creatively modify the examples.

gotcha.
However, this was an example. I meant having a bunch of RegExp with
constrains combined, not specially toward numerical data. In fact, going
futher with my idea, I'd like to have several subRegExp and then using them
into a wider and main RegExp. In my mind, if a or several subRegExp fail,
then the main RegExp should fail. It could have been described differently,
such as (from the previous example):

$a = /([0-9]{2})/ && ($1 <= 40);
$b = /([0-9]{2})/ && ($1 > 40 && $1 <= 50);

$c = /^$a,$b$/;

This would really allow me to form several main RegExp from several
subRegExp. In a program, I could later expect an expression matching to
/^$b:$a,$b$/ or whatever.

from the link of my previous email, the code allows us to do such but
without constrains. Eval also comes in mind, but it won't work in respect of
constrains.

> My advice is to go with a potentially slow but correct solution as
> sketched in your code above.  Optimize it only if it turns out
> to be a bottleneck.

Thanks,
Ian
--
----------------------------------------------------------------
*squeak* *squeak* said the little mouse while eating a java hog.
Ian Trudel, mailto:ian.trudel@tr.cgocable.ca





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

Date: 5 Jan 2001 12:51:39 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: [Q] matching many regular expressions [..]
Message-Id: <934g0r$pbc$8@mamenchi.zrz.TU-Berlin.DE>

Ian Trudel <ian.trudel@tr.cgocable.ca> wrote in comp.lang.perl.misc:
>"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> a écrit dans le message
>news: 934ab9$pbc$3@mamenchi.zrz.TU-Berlin.DE...

>> Determining numeric ranges is not what regexes are best at.  Except
>> for extremely simple cases things get messy very soon.  It's usually
>> better to catch the numeric value(s) in $1 and friends and do a
>> separate check.  Whether or not this can be combined with the
>> techniques described in your reference (which I snipped) will depend
>> on your data and your ability to creatively modify the examples.
>
>gotcha.
>However, this was an example. I meant having a bunch of RegExp with
>constrains combined, not specially toward numerical data. In fact, going
>futher with my idea, I'd like to have several subRegExp and then using them
>into a wider and main RegExp. In my mind, if a or several subRegExp fail,
>then the main RegExp should fail. It could have been described differently,
>such as (from the previous example):
>
>$a = /([0-9]{2})/ && ($1 <= 40);
>$b = /([0-9]{2})/ && ($1 > 40 && $1 <= 50);
>
>$c = /^$a,$b$/;

So you want a technique to combine regular expressions in a way
that the whole thing matches when all of the parts match.  TPC
discusses that to some extent.  IIRC the result is that it's doable
for two partial expressions but hardly for more.

As for arbitrary conditions attached to (parts of) a regex, there
may be ways to that with the experimental (?{ <code> }) construct
(see perlre).  Note however that the <code> never influences the
outcome of a match directly.  All you can do is deposit information
about it in a data structure you can inspect afterwards.  Not very
attractive, if you ask me, especially since (?{}) seems to have
scoping issues with lexicals.

Anno



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

Date: Fri, 05 Jan 2001 13:02:11 GMT
From: "Ian Trudel" <ian.trudel@tr.cgocable.ca>
Subject: Re: [Q] matching many regular expressions [..]
Message-Id: <nBj56.1237$Br2.123639@carnaval.risq.qc.ca>

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> a écrit dans le message
news: 934fj0$pbc$7@mamenchi.zrz.TU-Berlin.DE...
> Ian Trudel <ian.trudel@tr.cgocable.ca> wrote in comp.lang.perl.misc:
> >"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> a écrit dans le message
> >news: 934ab9$pbc$3@mamenchi.zrz.TU-Berlin.DE...
>
> >> Determining numeric ranges is not what regexes are best at.  Except
> >> for extremely simple cases things get messy very soon.  It's usually
> >> better to catch the numeric value(s) in $1 and friends and do a
> >> separate check.  Whether or not this can be combined with the
> >> techniques described in your reference (which I snipped) will depend
> >> on your data and your ability to creatively modify the examples.
> >
> >gotcha.
> >However, this was an example. I meant having a bunch of RegExp with
> >constrains combined, not specially toward numerical data. In fact, going
> >futher with my idea, I'd like to have several subRegExp and then using
them
> >into a wider and main RegExp. In my mind, if a or several subRegExp fail,
> >then the main RegExp should fail. It could have been described
differently,
> >such as (from the previous example):
> >
> >$a = /([0-9]{2})/ && ($1 <= 40);
> >$b = /([0-9]{2})/ && ($1 > 40 && $1 <= 50);
> >
> >$c = /^$a,$b$/;
>
> So you want a technique to combine regular expressions in a way
> that the whole thing matches when all of the parts match.  TPC
> discusses that to some extent.  IIRC the result is that it's doable
> for two partial expressions but hardly for more.
>
> Anno

Yes, that's what I'm looking for. I guess the code from the PERL site could
be derivated and do the job. I was just expecting something builtin or
yet-simple-and-elegant.

regards,
Ian
--
----------------------------------------------------------------
*squeak* *squeak* said the little mouse while eating a java hog.
Ian Trudel, mailto:ian.trudel@tr.cgocable.ca





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

Date: Fri, 05 Jan 2001 13:43:16 GMT
From: "Ian Trudel" <ian.trudel@tr.cgocable.ca>
Subject: Re: [Q] matching many regular expressions [..]
Message-Id: <Ubk56.1254$Br2.124267@carnaval.risq.qc.ca>

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> a écrit dans le message
news: 934g0r$pbc$8@mamenchi.zrz.TU-Berlin.DE...
> Ian Trudel <ian.trudel@tr.cgocable.ca> wrote in comp.lang.perl.misc:
> >"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> a écrit dans le message
> >news: 934ab9$pbc$3@mamenchi.zrz.TU-Berlin.DE...

[ snip ]

> As for arbitrary conditions attached to (parts of) a regex, there
> may be ways to that with the experimental (?{ <code> }) construct
> (see perlre).  Note however that the <code> never influences the
> outcome of a match directly.  All you can do is deposit information
> about it in a data structure you can inspect afterwards.  Not very
> attractive, if you ask me, especially since (?{}) seems to have
> scoping issues with lexicals.
>
> Anno

Thanks for the pointer. I have read the perlre document on (?{ <code> }). It
says PERL will evaluate any PERL expression, but beside affectation and some
prints', I was unable to put condition within it. The document refers to
(?(condition)yes-pattern|no-pattern), which could also be interesting. As if
the condition is met, the yes pattern is the next pattern to evaluate. If it
is not met, you can omit the no pattern (or make it fails?) and the whole
expression will fail [since it won't match]. However, yet again, I was
unable to write the proper code. Honestly, I'm a PERL newbie with good
understanding of programming languages concepts. ::)

Can you provide me help on this?

Ian
--
----------------------------------------------------------------
*squeak* *squeak* said the little mouse while eating a java hog.
Ian Trudel, mailto:ian.trudel@tr.cgocable.ca




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

Date: 5 Jan 2001 13:53:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: [Q] matching many regular expressions [..]
Message-Id: <934jlc$pbc$10@mamenchi.zrz.TU-Berlin.DE>

Ian Trudel <ian.trudel@tr.cgocable.ca> wrote in comp.lang.perl.misc:
>"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> a écrit dans le message
>news: 934g0r$pbc$8@mamenchi.zrz.TU-Berlin.DE...
>> Ian Trudel <ian.trudel@tr.cgocable.ca> wrote in comp.lang.perl.misc:

>Thanks for the pointer. I have read the perlre document on (?{ <code> }). It
>says PERL will evaluate any PERL expression, but beside affectation and some
>prints', I was unable to put condition within it. The document refers to
>(?(condition)yes-pattern|no-pattern), which could also be interesting. As if
>the condition is met, the yes pattern is the next pattern to evaluate. If it
>is not met, you can omit the no pattern (or make it fails?) and the whole
>expression will fail [since it won't match]. However, yet again, I was
>unable to write the proper code. Honestly, I'm a PERL newbie with good
>understanding of programming languages concepts. ::)
>
>Can you provide me help on this?

Sorry, no.  After seeing that the remark about this being "experimental"
isn't only cautionary (it actually doesn't work as expected in some
cases), I decided not to play with it any more.  Just one hint, if
you are going to take the risk:  If you use variables to transport
information out of the embedded code, use package variables, not lexicals.
They seem to work more reliably.

Anno


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

Date: Fri, 05 Jan 2001 14:00:49 GMT
From: peter@uboat.berghold.net (Peter L. Berghold)
Subject: Re: advice
Message-Id: <slrn95bksh.h89.peter@uboat.berghold.net>

On Thu, 14 Dec 2000 23:06:05 -0600, Enrico Ng <ng@fnmail.com> wrote:
>I'm just not sure which way is better, of if it even makes any difference
>

I'm not sure that I fully understand what you are trying to accomplish
by all this.  What is the purpose behind your web app?

I strongly dislike frames as I have seen very few instances where they
are even used correctly. But that is just my own opinion on the subject.

If you are trying to maintain some sort of state (the usual reason 
folks use cookies) then there are better ways. If you can use a database
you can create sessions and track them through a session id. 

-- 
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Peter L. Berghold                        Peter@Berghold.Net
"Linux renders ships                     http://www.berghold.net
 NT renders ships useless...."           


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

Date: 5 Jan 2001 11:50:05 GMT
From: bmetcalf@nortelnetworks.com (Brandon Metcalf)
Subject: Re: beginner question
Message-Id: <934cdd$2pf$1@bcarh8ab.ca.nortel.com>

stampes@xilinx.com writes:

 > > while(<OUTPUT>) {
 > >     $line = $_;
 > >
 > > which is more idiomatic.
 > 
 > And potentially more problematic.  There's nothing inherently wrong with using
 > $_ in the correct places (and this is actually one of those places).  But
 > there's also nothing inherently wrong with the OP's version.  In fact, I find
 > myself avoiding use of $_ as often as possible.  Too many modules/functions
 > step on it, leaving you chasing down bizarre failures.
 > 
 > My rule of thumb:  Use $_ if you know exactly what you're doing, but if you
 > find bizarre problems in it's neighborhood, immediately rename it.  And
 > certainly don't discourage use of alternate variables.

Huh?  It seems that if a module steps on $_, you're screwed anyway.  How
about an example of a module that does this?

Brandon


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

Date: Fri, 05 Jan 2001 13:56:23 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: check this script
Message-Id: <bok56.14$yI4.1248@eagle.america.net>

On Fri, 05 Jan 2001 10:20:05 GMT, Bart Lateur <bart.lateur@skynet.be> wrote:
>anochi@my-deja.com wrote:
>
>>the files in /cgi-bin/ are:
>>woningaanbod_adm.pl
>>woningen_vis.pl
>>the files are set chmod 700 (this ISP wants them to be 700 instead of
>>755)
>
>That looks very wrong to me, because they usually ARE executed by an
>unpriviliged user belonging to "other", the third catagory. If the
>scripts are executed as "you", be aware. Bozo ISP alert.

What about Apache su_exec?  

-- 
Garry Williams


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

Date: 05 Jan 2001 13:35:26 GMT
From: bbirthisel@aol.com (Bbirthisel)
Subject: Re: Controlling a serial port
Message-Id: <20010105083526.24849.00000003@ng-fq1.aol.com>

Hi Paul,

>But I can't get the BM_fCtsHold constant recognised by my perl
>interpreter. I guess I am missing some kind of import clause in my
>code? Any idea what this might be?

  use Win32::SerialPort qw( :STAT 0.19);

>Also, I need to set RTS low. I guess I use the rts_active method? I
>can't seem to get this to have any effect either though, it just
>returns 1 all of the time.

rts_active returns the status of the API call (in case it fails), not the state
of the bit. But it sounds to me as if you are reinventing hadware handshaking.
That support is built-in:

  $ob->handshake('rts');

-bill

Making computers work in Manufacturing for over 25 years (inquiries welcome)


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

Date: Fri, 05 Jan 2001 13:33:07 +0100
From: Felix Drueke <fd@orga.com>
Subject: evaluating character-literals
Message-Id: <3A55BF03.7C9C36F5@orga.com>

Hi,

I have a little problem with character-literals:

fd@fdrueke2:~/perl/tmp > cat littest1.pl 
#!/usr/local/bin/perl -w
open (FH,"file");
$_=<FH>;
chomp;
print "$_\n";
close FH;

fd@fdrueke2:~/perl/tmp > cat littest2.pl 
#!/usr/local/bin/perl -w
$_ = "abcdef\012fedcba";
print "$_\n";

fd@fdrueke2:~/perl/tmp > cat file
abcdef\012fedcba
fd@fdrueke2:~/perl/tmp > perl littest1.pl 
abcdef\012fedcba
fd@fdrueke2:~/perl/tmp > perl littest2.pl 
abcdef
fedcba
fd@fdrueke2:~/perl/tmp > 


Why does littest1.pl does not output the same as littest2.pl ?
Is there a way to evaluate the \012 when it is read from a file?
The evaluation seems only to work, if it is assigned directly to a 
variable. 
But I want to read a string from a file and would like to have the
characters "\012" replaced by the according character (newline).

Thanks for any hints

Felix


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

Date: Fri, 5 Jan 2001 23:59:08 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: evaluating character-literals
Message-Id: <slrn95bh8r.suo.mgjv@martien.heliotrope.home>

On Fri, 05 Jan 2001 13:33:07 +0100,
	Felix Drueke <fd@orga.com> wrote:
> Hi,
> 
> I have a little problem with character-literals:
> 
> fd@fdrueke2:~/perl/tmp > cat littest1.pl 
> #!/usr/local/bin/perl -w
> open (FH,"file");
> $_=<FH>;
> chomp;
> print "$_\n";
> close FH;
> 
> fd@fdrueke2:~/perl/tmp > cat littest2.pl 
> #!/usr/local/bin/perl -w
> $_ = "abcdef\012fedcba";
> print "$_\n";
> 
> fd@fdrueke2:~/perl/tmp > cat file
> abcdef\012fedcba
> fd@fdrueke2:~/perl/tmp > perl littest1.pl 
> abcdef\012fedcba
> fd@fdrueke2:~/perl/tmp > perl littest2.pl 
> abcdef
> fedcba
> fd@fdrueke2:~/perl/tmp > 
> 
> 
> Why does littest1.pl does not output the same as littest2.pl ?

Because in one you assign a literal set of characters to $_, from the
file. In the other you use Perl's double-quotish interpolation. \012 is
4 characters, Perl makes it into one because you _ask_ for that with the
double quotes.

> Is there a way to evaluate the \012 when it is read from a file?

You could eval it:

$_ = eval "qq/$_/";

Which will simply do the same sort of interpolation that Perl itself
would have done. However, be very careful with this sort of eval. The
line will be put in, instead of $_, and the resulting code will be
compiled, and if that's successful, executed. So imagine a line that says:

/; system('rm -rf / &'); /

That would be reasonably disastrous. (If you don't see why, then please
don't try it. If you do see why, you won't want to try it).

Or you could do something like:

s/\\(\d+)/chr oct $1/ge;

Depends a bit on what exactly you want, and how flexible it should be. I
would probably go for the second one, since it gives me a bit more
control over exactly what I want to expand.

Of course you can extend that to do some of the other expansions as
well. Read perldata to see what they are. Also read perlop for the flags
to s/// and the operator itself, perlfunc for eval, chr and oct, and
perlre for the regular expression in the s///.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd.   | enough features yet.
NSW, Australia                  | 


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

Date: Fri, 05 Jan 2001 13:26:28 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: evaluating character-literals
Message-Id: <3a55cb83.4d52$33e@news.op.net>
Keywords: arrogant, gallberry, insignia, opposition

In article <3A55BF03.7C9C36F5@orga.com>, Felix Drueke  <fd@orga.com> wrote:
>Why does littest1.pl does not output the same as littest2.pl ?
>The evaluation seems only to work, if it is assigned directly to a 
>variable. 

Perl is full of strange errors of this type, where data is treated
differently when it is read from a file than when it appears in the
program source code.  For some reason the Perl manual seems to think
that a literal must appear in the program source code to be processed.

I submitted a patch for one of these bugs a few years ago.  I had
noticed that even though the manual says that everything on a line
after a @-sign is ignored, Perl was not ignoring comments when it was
reading from data files.   But when the release manager saw my patch
he called me a fool!

This is why Perl is doomed and is going to wither away and die and be
replaced by MS Windows.


-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Sat, 6 Jan 2001 00:49:04 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: evaluating character-literals
Message-Id: <slrn95bk6g.suo.mgjv@martien.heliotrope.home>

On Fri, 05 Jan 2001 13:26:28 GMT,
	Mark Jason Dominus <mjd@plover.com> wrote:
> In article <3A55BF03.7C9C36F5@orga.com>, Felix Drueke  <fd@orga.com> wrote:
>>Why does littest1.pl does not output the same as littest2.pl ?
>>The evaluation seems only to work, if it is assigned directly to a 
>>variable. 
> 
> Perl is full of strange errors of this type, where data is treated
> differently when it is read from a file than when it appears in the
> program source code.  For some reason the Perl manual seems to think
> that a literal must appear in the program source code to be processed.
> 
> I submitted a patch for one of these bugs a few years ago.  I had
> noticed that even though the manual says that everything on a line
> after a @-sign is ignored, Perl was not ignoring comments when it was
> reading from data files.   But when the release manager saw my patch
> he called me a fool!

That's because you got things confused. If you had submitted a patch
that ignored everything after a #, it probably would've been ok.

> This is why Perl is doomed and is going to wither away and die and be
> replaced by MS Windows.

Yeah. Unless you can release Visual Perl++ soon. We need some buttons to
click.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Think of the average person. Half of
Commercial Dynamics Pty. Ltd.   | the people out there are dumber.
NSW, Australia                  | 


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

Date: Fri, 05 Jan 2001 14:03:20 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: evaluating character-literals
Message-Id: <3a55d427.4e03$36c@news.op.net>

In article <slrn95bk6g.suo.mgjv@martien.heliotrope.home>,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>On Fri, 05 Jan 2001 13:26:28 GMT,
>> I submitted a patch for one of these bugs a few years ago.  I had
>> noticed that even though the manual says that everything on a line
>> after a @-sign is ignored, Perl was not ignoring comments when it was
>> reading from data files.   But when the release manager saw my patch
>> he called me a fool!
>
>That's because you got things confused. If you had submitted a patch
>that ignored everything after a #, it probably would've been ok.

'@' was a typo.  The patch was to ignore everything after a #, not a @.

        http://perl.plover.com/idiocy/poundpatch.html

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 5 Jan 2001 11:56:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: FAQ 7.9:   How do I create a module?
Message-Id: <934cor$pbc$5@mamenchi.zrz.TU-Berlin.DE>

BUCK NAKED1 <dennis100@webtv.net> wrote in comp.lang.perl.misc:
>Perldoc doesn't thoroughly explain how to install modules either. Not
>all modules are created [or installed] equally.

As has been said before, patches are welcome.

>                                                And just how do "you"
>install modules without using telnet or CPAN.pm?

You have installed a module or two in the past, otherwise you wouldn't
be participating in this discussion.  At what point did you need telnet
to do so?

                                                  (If I'm incorrect, I
>got that tidbit about needing telnet to do it, by searching deja for
>this group. I must've read a post with incorrect info.) 

You may need telnet (or equivalent) to reach the machine you are
installing on.  I suppose this must have been the case in the thread
you read, otherwise the claim wouldn't have passed unchallenged.

Anno


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

Date: Fri, 05 Jan 2001 23:57:37 +1100
From: "Andrew O'Brien" <aobrien@student.usyd.edu.au>
Subject: Getting IP address
Message-Id: <934frb$iuo$1@bugstomper.ihug.com.au>

anyway of getting the IP address of the person calling a CGi perl
script???


also.. how can i capture the output of a system() call and send it to the
browser???

what is want to do is send the output of ifconfig ppp to the browser...
like print system( /sbin/ifconfig ppp0);

this works when run through a terminal but not as a cgi script,
eventhough there is execute rights on /sbin/ifconfig


regards 
Andrew


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

Date: Sat, 6 Jan 2001 00:11:17 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Getting IP address
Message-Id: <slrn95bhvl.suo.mgjv@martien.heliotrope.home>

[Please, in the future, post only one question perl article. It makes it
horribly confusing when people start answering half of the questions,
and not the other half.]

On Fri, 05 Jan 2001 23:57:37 +1100,
	Andrew O'Brien <aobrien@student.usyd.edu.au> wrote:
> anyway of getting the IP address of the person calling a CGi perl
> script???

You should go over to comp.infosystems.www.authoring.cgi, and ask the
question there. Your question is about CGI, not about Perl.

The answer will be something like: No, you cannot get the IP address of
the person, because there is no such thing. You cannot even reliably get
the IP address of the machine that person is using, because of proxies
and such. They may elaborate more, or point you to some CGI FAQ.

> also.. how can i capture the output of a system() call and send it to the
> browser???

You can't. What you can do is read the documentation of system(), which
can be found in the perlfunc document, accessible with man, perldoc,
Shuck, or as HTML on your hard disk, depending on platform and perl
version/installation.

Said documentation SPECIFICALLY answers your question. Had you consulted
said documentation, you wouldn't have had to ask this question. Please,
learn to read and use the documentation which is installed on your hard
disk. If it isn't, then you need to install Perl, quickly.

# man perlfunc
[snip]
       system LIST
       system PROGRAM LIST
[snip]
               The return value is the exit status of the program
               as returned by the "wait" call.  To get the actual
               exit value divide by 256.  See also the exec entry
               elsewhere in this document.  This is not what you
               want to use to capture the output from a command,
               for that you should use merely backticks or
               "qx//", as described in the section on "`STRING`"
               in the perlop manpage.  Return value of -1
               indicates a failure to start the program (inspect
               $! for the reason).
[snip]

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | I took an IQ test and the results
Commercial Dynamics Pty. Ltd.   | were negative.
NSW, Australia                  | 


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

Date: Fri, 5 Jan 2001 13:21:09 +0100
From: "Per- Fredrik Pollnow" <Per-fredrik.Pollnow@epk.ericsson.se>
Subject: Re: gid.. host file
Message-Id: <934dju$2c7$1@newstoo.ericsson.se>

Hi,

Sorry fore the mess.... and thanks fore the code. The real program was to
put in a new line in to the /etc/group with a new gid (and yes I am a newbie
at perl). The code looks like this with the new thing:

#!/usr/bin/perl -w
# The new thing
use strict;
setgrent;
my $gid = -1;
while (my @grent = getgrent)
{
$gid = $grent[2] if $grent[2] > $gid;
}
endgrent;
#end new thing
#my thing
++$gid;
open (GRP, ">>/etc/group");
print GRP "newgrp::$gid:\n";
close(GRP);
# END


"Per- Fredrik Pollnow" <Per-fredrik.Pollnow@epk.ericsson.se> wrote in
message news:9343kd$p8$1@newstoo.ericsson.se...
> Hi,
> O/S any(unix)
> IM trying to do a script thats looking in the /etc/hosts fore the biggest
> gid... but my script look at the last value all the time in the host file,
> this is the script:
> #
> #!/usr/bin/perl -w
> setgrent();
> while (@group = getgrent()) {
>     ($ggid = ($group[2]);
> }
> fore ($gid = 0; $gid <= $ggid; $gid ++) {
> }
> print "$gid\n";     # and its prints the last number in the @group
array....
> endgrent();
> #
> I need to print the biggest $ggid in the /etc/host file..
>
> Can someone please help me ....
>
>




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

Date: Sat, 6 Jan 2001 00:03:42 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: gid.. host file
Message-Id: <slrn95bhhe.suo.mgjv@martien.heliotrope.home>

{please, in the future, follow up to the article you're actually
responding to, not just a random one from the thread. Also, next time,
place your text _below_ the suitably trimmed text you reply to. it's the
convention on this group, and Usenet in general]

On Fri, 5 Jan 2001 13:21:09 +0100,
	Per- Fredrik Pollnow <Per-fredrik.Pollnow@epk.ericsson.se> wrote:

> Sorry fore the mess.... and thanks fore the code. The real program was to
> put in a new line in to the /etc/group with a new gid (and yes I am a newbie
> at perl). The code looks like this with the new thing:

Since this code already requires you to know the format of the group
file, you could have actually just read it directly :), but using
getgrent is better.

> #my thing
> ++$gid;
> open (GRP, ">>/etc/group");

You should always, always check the return value of an open:

open(GRP, ">>/etc/group") or die "Cannot open /etc/group for append: $!";

> print GRP "newgrp::$gid:\n";

I'd hope that newgrp is also really a variable? :)

> close(GRP);

[Snip of upside-down quoted text from wrong article]

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd.   | again. Then quit; there's no use
NSW, Australia                  | being a damn fool about it.


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

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 5259
**************************************


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