[23071] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5292 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 30 11:05:55 2003

Date: Wed, 30 Jul 2003 08:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 30 Jul 2003     Volume: 10 Number: 5292

Today's topics:
        Converting from decimal to hex <anders@XXX.redakula.net>
    Re: Converting from decimal to hex <abigail@abigail.nl>
    Re: Currying functions <ed@membled.com>
    Re: Discrepancy in Time? <john.thetenant-s@moving-picture.com>
    Re: Discrepancy in Time? <cat@no-spam.com>
    Re: Discrepancy in Time? <cat@no-spam.com>
    Re: Discrepancy in Time? <cat@no-spam.com>
    Re: Driving me mad.  Can't see the error in this code.. <Ed+nospam@ewildgoose.demon.co.uk@>
    Re: How do you Call a Perl subroutine with a variable n <noreply@gunnar.cc>
    Re: How do you Call a Perl subroutine with a variable n <noreply@gunnar.cc>
        Re: <rrklier@tychen.franken.de>
        regular expression question <bbbart@kotnet.org>
    Re: regular expression question (Greg Bacon)
    Re: regular expression question (Sam Holden)
    Re: regular expression question <abigail@abigail.nl>
    Re: remote readdir() <int.consultNOCAPITALS@macmail.com>
    Re: split alternative using regexp? <peb@bms.umist.ac.uk>
        weird "perl -e" behaviour <zebuwin@yahoo.fr>
    Re: weird "perl -e" behaviour <zebuwin@yahoo.fr>
    Re: weird "perl -e" behaviour (Villy Kruse)
    Re: weird "perl -e" behaviour <zebuwin@yahoo.fr>
    Re: Win32 Ole <mikeflan@earthlink.net>
    Re: Win32 Ole <mikeflan@earthlink.net>
    Re: zero but true? <scriptyrich@yahoo.co.uk>
    Re: zero but true? (Villy Kruse)
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 30 Jul 2003 16:31:47 +0200
From: "Anders Bystrup" <anders@XXX.redakula.net>
Subject: Converting from decimal to hex
Message-Id: <pan.2003.07.30.14.31.47.175843@XXX.redakula.net>

Hi.

I have an array consisting of mac addresses in decimal form seperated by :
Like this:
0:0:33:195:37:6 0:0:180:75:15:17 and so on

I now need to convert the decimal numbers into hex on the following form:
00:e0:98:9b:ce:6f 00:e0:98:a4:db:41

Is it possible to do this using a search and replace or how would you do
this?

/Anders


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

Date: 30 Jul 2003 14:39:48 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Converting from decimal to hex
Message-Id: <slrnbifm5k.sfr.abigail@alexandra.abigail.nl>

Anders Bystrup (anders@XXX.redakula.net) wrote on MMMDCXX September
MCMXCIII in <URL:news:pan.2003.07.30.14.31.47.175843@XXX.redakula.net>:
$$  Hi.
$$  
$$  I have an array consisting of mac addresses in decimal form seperated by :
$$  Like this:
$$  0:0:33:195:37:6 0:0:180:75:15:17 and so on
$$  
$$  I now need to convert the decimal numbers into hex on the following form:
$$  00:e0:98:9b:ce:6f 00:e0:98:a4:db:41
$$  
$$  Is it possible to do this using a search and replace or how would you do
$$  this?


    $mac =~ s/(\d+)/sprintf "%02x" => $1/ge;

or

    $mac = join ":" => map {sprintf "%02x" => $_} split /:/ => $mac;

Abigail
-- 
perl  -e '$_ = q *4a75737420616e6f74686572205065726c204861636b65720a*;
          for ($*=******;$**=******;$**=******) {$**=*******s*..*qq}
          print chr 0x$& and q
          qq}*excess********}'


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

Date: 30 Jul 2003 13:37:15 +0100
From: Ed Avis <ed@membled.com>
Subject: Re: Currying functions
Message-Id: <l1ispkw5qb.fsf@budvar.future-i.net>

Marcin 'Qrczak' Kowalczyk <qrczak@knm.org.pl> writes:

>>If in Perl you want to use a regexp which is not known until run
>>time, but on the other hand expect that the same regexp will be used
>>often, then one way to get the right result is to construct a
>>closure:
> 
>It's simpler to write qr/$pattern/ - it's a scalar which you can
>store in a variable.

Apologies - I was still thinking about olden days when qr// didn't
exist.  Yes, it seems you can do

    my $letter = 'a';
    my $r0 = qr/$letter/;
    $letter = 'b';
    my $r1 = qr/$letter/;

    for (qw(a b)) {
        print "testing $_\n";
        print "r0\n" if $_ =~ $r0;
        print "r1\n" if $_ =~ $r1;
    }

So it looks like the regexp is compiled when qr// is evaluated.  This
is a much simpler way to get dynamically-generated (yet compiled once)
regular expressions than the old way of using closures.

-- 
Ed Avis <ed@membled.com>


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

Date: Wed, 30 Jul 2003 11:13:15 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: Discrepancy in Time?
Message-Id: <20030730111315.0be3692e.john.thetenant-s@moving-picture.com>

On Wed, 30 Jul 2003 09:50:13 GMT
jason@jumpsql.com (Jason Quek) wrote:
>
> When I convert "26 Oct 2003" to epoch seconds,
> 
> #-----------------------------------------------------------------
> use Time::Local;
> $from = timelocal(0, 0, 0, 26, 9, 2003);
> # $from == 1067140800;
> #-----------------------------------------------------------------
> 
> When I convert "27 Oct 2003" to epoch seconds,
> 
> #-----------------------------------------------------------------
> use Time::Local;
> $from = timelocal(0, 0, 0, 26, 9, 2003);
> # $to == 1067230800;
> #-----------------------------------------------------------------
> 
> #-----------------------------------------------------------------
> $difference = $to - $from;
> # $difference == 90000;
> #-----------------------------------------------------------------
> 
> Shouldn't the difference between the 26th and 27th be 86400
> (60*60/24)? Where did the extra 1 hour come from?
> 
> 
> Does anybody know why this happens?
> 
> 

sounds like DST ends.  try timegm() instead of timelocal().



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail


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

Date: Wed, 30 Jul 2003 21:02:26 +1000
From: Cat <cat@no-spam.com>
Subject: Re: Discrepancy in Time?
Message-Id: <3F27A5C1.2CB31D07@no-spam.com>

Jason Quek wrote:
> 
> When I convert "26 Oct 2003" to epoch seconds,
> 
> #-----------------------------------------------------------------
> use Time::Local;
> $from = timelocal(0, 0, 0, 26, 9, 2003);
> # $from == 1067140800;
> #-----------------------------------------------------------------
> 
> When I convert "27 Oct 2003" to epoch seconds,
> 
> #-----------------------------------------------------------------
> use Time::Local;
> $from = timelocal(0, 0, 0, 26, 9, 2003);
> # $to == 1067230800;
> #-----------------------------------------------------------------
> 
> #-----------------------------------------------------------------
> $difference = $to - $from;
> # $difference == 90000;
> #-----------------------------------------------------------------
> 
> Shouldn't the difference between the 26th and 27th be 86400
> (60*60/24)? Where did the extra 1 hour come from?
> 
> Does anybody know why this happens?
> 

You should copy and paste... that way we can see the _exact_ code. 

When I run the program below, I get
From:           1064498400
To:             1064584800
Difference:     86400

#!/bin/perl
use strict;
use warnings;
use diagnostics;

use Time::Local;

my $from       = timelocal(0, 0, 0, 26, 8, 103);
my $to         = timelocal(0, 0, 0, 27, 8, 103);
my $difference = $to - $from;


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

Date: Wed, 30 Jul 2003 21:12:20 +1000
From: Cat <cat@no-spam.com>
Subject: Re: Discrepancy in Time?
Message-Id: <3F27A814.D1EF712F@no-spam.com>

Please ignore this message.  I was supposed to squash it, but sent it
in mistake  :(

Cat wrote:
> 
> Jason Quek wrote:
> >
> > When I convert "26 Oct 2003" to epoch seconds,
> >
> > #-----------------------------------------------------------------
> > use Time::Local;
> > $from = timelocal(0, 0, 0, 26, 9, 2003);
> > # $from == 1067140800;
> > #-----------------------------------------------------------------
> >
> > When I convert "27 Oct 2003" to epoch seconds,
> >
> > #-----------------------------------------------------------------
> > use Time::Local;
> > $from = timelocal(0, 0, 0, 26, 9, 2003);
> > # $to == 1067230800;
> > #-----------------------------------------------------------------
> >
> > #-----------------------------------------------------------------
> > $difference = $to - $from;
> > # $difference == 90000;
> > #-----------------------------------------------------------------
> >
> > Shouldn't the difference between the 26th and 27th be 86400
> > (60*60/24)? Where did the extra 1 hour come from?
> >
> > Does anybody know why this happens?
> >
> 
> You should copy and paste... that way we can see the _exact_ code.
> 
> When I run the program below, I get
> From:           1064498400
> To:             1064584800
> Difference:     86400
> 
> #!/bin/perl
> use strict;
> use warnings;
> use diagnostics;
> 
> use Time::Local;
> 
> my $from       = timelocal(0, 0, 0, 26, 8, 103);
> my $to         = timelocal(0, 0, 0, 27, 8, 103);
> my $difference = $to - $from;


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

Date: Wed, 30 Jul 2003 21:13:50 +1000
From: Cat <cat@no-spam.com>
Subject: Re: Discrepancy in Time?
Message-Id: <3F27A86E.7B560B21@no-spam.com>

Jason Quek wrote:
> 
> When I convert "26 Oct 2003" to epoch seconds,
> 
> #-----------------------------------------------------------------
> use Time::Local;
> $from = timelocal(0, 0, 0, 26, 9, 2003);
> # $from == 1067140800;
> #-----------------------------------------------------------------
> 
> When I convert "27 Oct 2003" to epoch seconds,
> 
> #-----------------------------------------------------------------
> use Time::Local;
> $from = timelocal(0, 0, 0, 26, 9, 2003);
> # $to == 1067230800;
> #-----------------------------------------------------------------
> 
> #-----------------------------------------------------------------
> $difference = $to - $from;
> # $difference == 90000;
> #-----------------------------------------------------------------
> 
> Shouldn't the difference between the 26th and 27th be 86400
> (60*60/24)? Where did the extra 1 hour come from?
> 
> Does anybody know why this happens?
> 

Daylight savings


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

Date: Wed, 30 Jul 2003 10:23:29 GMT
From: "Edward Wildgoose" <Ed+nospam@ewildgoose.demon.co.uk@>
Subject: Re: Driving me mad.  Can't see the error in this code...
Message-Id: <B0NVa.1257664$ZC.184341@news.easynews.com>

> This is just a guess, but is the code example EXACTLY as it is in the
> script?  Complete with the command on separate lines (same scalar
> variable, but on separate lines for readability)?

Nope, sorry, got caught by line wrapping.  It was all on one line when I
posted it...

I have worked around it for the time being by using the perl based RCS code
in Twiki, however, it had a silly bug in it which took me a while to track
down (it scrambles the dates accidently if you do two quick edits).

This is very pecualiar, but I can only assume that there is something
strange happening in the way the shell is setup in win32 and the RCS command
is not happy (but failing silently).

Thanks to anyone who looked at it.

Ed




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

Date: Wed, 30 Jul 2003 12:03:47 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <bg85b9$ll5ot$1@ID-184292.news.uni-berlin.de>

Uri Guttman wrote:
>>>>>> "GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
>   GH> Steven Kuo wrote:
>   >> our $bar = 'BAR';    # package scoped
>   >> my  $foo = 'bar';
>   >> my $symref = \$$foo; # symbolic reference
> 
> that is a symbolic DEreference of $foo and then a hard reference to
> $bar. $symref has the value of \$bar. the var $symref is poorly
> named as it really holds a hard ref.

With that comment, I'm able to understand the reasoning.

> it is a hard ref to $bar, not to 'BAR'.

Thanks for correcting me on that.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Wed, 30 Jul 2003 12:03:50 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How do you Call a Perl subroutine with a variable name?
Message-Id: <bg85bc$ll5ot$2@ID-184292.news.uni-berlin.de>

Uri Guttman wrote:
> GH> But how about:
> 
>   GH>      sub foo { print "foo\n" }
>   GH>      my $bar = 'foo';
>   GH>      my $code_ref = \&$bar;
> 
>   GH> Is $code_ref in that example not a "true" coderef? Even if a
>   GH> symref construct was used for _creating_ $code_ref, don't you
>   GH> agree that $code_ref is as hard as in the two other examples?
> 
> it is a hard ref. but it is tainted by how it was created.

Okay, that does make sense.

> how you get [a real coderef] is the whole point of this thread. i
> said that coderefs are generally a compile time thing but as you
> showed it can be done at runtime. that doesn't make it good.

Thanks. Now I think I understand the whole picture. :)

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Wed, 30 Jul 2003 13:17:59 +0000 (UTC)
From: Rainer Klier <rrklier@tychen.franken.de>
Subject: Re:
Message-Id: <slrnbifhc7.25u.rrklier@localhost.localdomain>

In article <tv%Ra.91979$TJ.5252351@twister.austin.rr.com>, Ron wrote:
> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
    ^                                                            ^
    |                                                            |

  here               you should change something or            there 

Rainer


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

Date: Wed, 30 Jul 2003 10:35:32 GMT
From: Bart Van Loon <bbbart@kotnet.org>
Subject: regular expression question
Message-Id: <UbNVa.749247$V9.63522550@amsnews02.chello.com>

Hello,

is it possible to make a regular expression match for the following 
situation:

I have a string, looking like 'foobarbarbar'. I don't know what foo is, 
nor what bar is, the only thing I know is that I have a string X, 
concatenated an undefined number of times with a string Y. My goal is to 
find out how many times this string Y (bar) is repeted, without knowing 
what it exactly is.

Something like ^.*(.*)*$ maybe?

greetings,
BBBart



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

Date: Wed, 30 Jul 2003 12:18:33 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: regular expression question
Message-Id: <vifdsp7phqg05c@corp.supernews.com>

In article <UbNVa.749247$V9.63522550@amsnews02.chello.com>,
    Bart Van Loon  <bbbart@kotnet.org> wrote:

: I have a string, looking like 'foobarbarbar'. I don't know what foo
: is, nor what bar is, the only thing I know is that I have a string X,
: concatenated an undefined number of times with a string Y. My goal is
: to find out how many times this string Y (bar) is repeted, without
: knowing what it exactly is.

    % cat try
    #! /usr/local/bin/perl

    use warnings;
    use strict;

    my $X = 'foo';
    my $Y = 'bar';

    my $re = qr/^ $X ($Y)+ $/x;

    for (qw/ foo foobarbarbar foobar barbarfoo /) {
        if (/$re/) {
            print "Match for [$_]\n";
        }
        else {
            print "No match for [$_]\n";
        }
    }
    % ./try
    No match for [foo]
    Match for [foobarbarbar]
    Match for [foobar]
    No match for [barbarfoo]

You may need to use quotemeta, depending on how you want to match.

Hope this helps,
Greg
-- 
I'm proud to be a taxpaying American, but I could be just as proud for
half the money!
    -- Will Rogers


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

Date: 30 Jul 2003 13:01:16 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: regular expression question
Message-Id: <slrnbifgcr.lrm.sholden@flexal.cs.usyd.edu.au>

On Wed, 30 Jul 2003 10:35:32 GMT, Bart Van Loon <bbbart@kotnet.org> wrote:
> Hello,
> 
> is it possible to make a regular expression match for the following 
> situation:
> 
> I have a string, looking like 'foobarbarbar'. I don't know what foo is, 
> nor what bar is, the only thing I know is that I have a string X, 
> concatenated an undefined number of times with a string Y. My goal is to 
> find out how many times this string Y (bar) is repeted, without knowing 
> what it exactly is.
> 
> Something like ^.*(.*)*$ maybe?

What's the point of a regular expression which matches all
strings (assumming /s is used)?

And do you use (.*)* because you want some extra added slowness?

My naive approach would be to use something like (assumming "undefined
number" means 2 or more - since otherwise it doesn't make sense):

$_='foobarbarbar';
if (/^(.+?)((.+)\3+)$/s) {
	print "X is $1\n";
	print "Y is $3\n";
	print "There are " . length($2)/length($3) . " repetitions of Y\n";
}

But that fails to match. However, /^(foo)((.+)\3+)$/ matches (and is what
I tested the code with).

Since (.+?) can match "foo", I think the first regular expression should
match (after a fair bit of backtracking - guess the second .+ might be
more efficient as .+?, but that's beside the point).

echo "foobarbarbar" | egrep '^(.+)((.+)\3+)$'

outputs "foobarbarbar" (I realise that \1 will be "foobar" and \2 "barbar"
so the match is slightly different), so it seems to do what I would expect.

Is this a bug in perl? Or is my knowedge of regexes faulty?

I suspect the second, but (other than embaressment) it can't hurt to ask.

-- 
Sam Holden



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

Date: 30 Jul 2003 13:24:28 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: regular expression question
Message-Id: <slrnbifhoc.sdd.abigail@alexandra.abigail.nl>

Greg Bacon (gbacon@hiwaay.net) wrote on MMMDCXX September MCMXCIII in
<URL:news:vifdsp7phqg05c@corp.supernews.com>:
!!  In article <UbNVa.749247$V9.63522550@amsnews02.chello.com>,
!!      Bart Van Loon  <bbbart@kotnet.org> wrote:
!!  
!! : I have a string, looking like 'foobarbarbar'. I don't know what foo
!! : is, nor what bar is, the only thing I know is that I have a string X,
!! : concatenated an undefined number of times with a string Y. My goal is
!! : to find out how many times this string Y (bar) is repeted, without
!! : knowing what it exactly is.
!!  
!!      % cat try
!!      #! /usr/local/bin/perl
!!  
!!      use warnings;
!!      use strict;
!!  
!!      my $X = 'foo';
!!      my $Y = 'bar';
!!  
!!      my $re = qr/^ $X ($Y)+ $/x;
!!  
!!      for (qw/ foo foobarbarbar foobar barbarfoo /) {
!!          if (/$re/) {
!!              print "Match for [$_]\n";
!!          }
!!          else {
!!              print "No match for [$_]\n";
!!          }
!!      }
!!      % ./try
!!      No match for [foo]
!!      Match for [foobarbarbar]
!!      Match for [foobar]
!!      No match for [barbarfoo]


But $X and $Y are unknown. The following ought to work:

    if (/^(.+?)(.+?)(\2+)$/) {
        printf "'%s': '%s' followed by %d times '%s'\n",
                $_, $1, 1 + length ($3) / length ($2), $2;
    }

except that it doesn't on 5.8.0. It does on 5.6.x and 5.005.


Abigail
-- 
BEGIN {$^H {q} = sub {pop and pop and print pop}; $^H = 2**4.2**12}
"Just "; "another "; "Perl "; "Hacker\n";


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

Date: Wed, 30 Jul 2003 15:56:08 +0100
From: "programmer" <int.consultNOCAPITALS@macmail.com>
Subject: Re: remote readdir()
Message-Id: <bg8mpg$6m4$1@pheidippides.axion.bt.co.uk>

> Is there a way to use readdir to get the directory structure of a
> remote server?  If not, is there another function that can do this?


I did this using Net::FTP and a recursive program that reads the root
directory, extracts the size of files and the name of directories.

It then calls itself for all directories, and accuumulates the sizes for all
files.




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

Date: Wed, 30 Jul 2003 15:17:41 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: split alternative using regexp?
Message-Id: <3f27dd53@news.umist.ac.uk>

Tassilo v. Parseval wrote:

> Also sprach Greg:
> 
>> I am trying to teach myself Perl regular expressions and one exercise
>> that I am having trouble with is duplicating the split function using
>> regular expressions.
> 
> Emulating split() with regexes sounds easier than it is. There is no
> generic way to turn a split statement into an equivalent match (at least
> none I know of). For instance, in a case like
> 
>     @p = split /a/, $string;
> 
> split() wont care whether $string begins, ends or even contains an 'a'.
> It'll just do the right thing. If you use a match instead, you have to
> take these different cases into account yourself. Take this:
>     
>     # the easy case
>     my $string = "bbabba";
>     my @parts  = $string =~ /(.*?)a/g;
>     print join "*", @parts;
>     __END__
>     bb*bb
> 
> This works as expected. But now prepend an 'a':
> 
>     my $string = "abbabba";
>     my @parts  = $string =~ /(.*?)a/g;
>     print join "*", @parts;
>     __END__
>     *bb*bb
> 
> So suddenly you end up having the empty string in $parts[0]. This could
> be fixed by adding a grep():

<snip>

Isn't this how split behaves as well? i.e. split would put 'undef' in 
$parts[0].

perl -le '$_ = "abbabba"; print join(":", split "a")'
:bb:bb

Paul


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

Date: 30 Jul 2003 13:58:54 +0200
From: Francois Wisard <zebuwin@yahoo.fr>
Subject: weird "perl -e" behaviour
Message-Id: <slrnbifcnu.n5.zebuwin@pingou.bluewin.ch>

Hi folks,

I encounter a strange "perl -e" behaviour since I'm running FreeBSD 5.1
(Perl 5.6.1). My one-liners are refused with strange error messages.

Some examples:

bash-2.05b$ perl -e "@a=('a'..'z');print $a[5]"
ARRAY(0x810115c)bash-2.05b$

or

bash-2.05b$ perl -e "$_="abc";s/b/c/g;print $_"
Undefined subroutine &main::ls called at -e line 1.

or even

bash-2.05b$ perl -e "@a=('a'..'z');print $#a"
Bareword found where operator expected at -e line 1, near "0a"
        (Missing operator before a?)
syntax error at -e line 1, next token ???

Anyone knows what happens there? I'm tired of writing files when a
one-liner should have sufficed.

TIA

Francois


-- 
"The main reception foyer was almost empty but Ford 
nevertheless weaved his way through it." 

- Ford making his way out of Milliways whilst under the 
influence of enough alchol to make a rhino sing. 


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

Date: 30 Jul 2003 14:02:24 +0200
From: Francois Wisard <zebuwin@yahoo.fr>
Subject: Re: weird "perl -e" behaviour
Message-Id: <slrnbifcug.n5.zebuwin@pingou.bluewin.ch>

On 30 Jul 2003 13:58:54 +0200, Francois Wisard wrote:
> bash-2.05b$ perl -e "$_="abc";s/b/c/g;print $_" 
> Undefined subroutine &main::ls called at -e line 1.

Should be "$_='abc';s/b/c/g;print $_" of course. Same error message

Francois


-- 
"Yes, it's the right planet, all right, " he said again. 
"Right planet, wrong universe. "


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

Date: 30 Jul 2003 12:46:16 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: weird "perl -e" behaviour
Message-Id: <slrnbiffgp.hh.vek@station02.ohout.pharmapartners.nl>

On 30 Jul 2003 13:58:54 +0200,
    Francois Wisard <zebuwin@yahoo.fr> wrote:


>Hi folks,
>
>I encounter a strange "perl -e" behaviour since I'm running FreeBSD 5.1
>(Perl 5.6.1). My one-liners are refused with strange error messages.
>
>Some examples:
>
>bash-2.05b$ perl -e "@a=('a'..'z');print $a[5]"
>ARRAY(0x810115c)bash-2.05b$
>
>or
>
>bash-2.05b$ perl -e "$_="abc";s/b/c/g;print $_"
>Undefined subroutine &main::ls called at -e line 1.
>
>or even
>
>bash-2.05b$ perl -e "@a=('a'..'z');print $#a"
>Bareword found where operator expected at -e line 1, near "0a"
>        (Missing operator before a?)
>syntax error at -e line 1, next token ???
>
>Anyone knows what happens there? I'm tired of writing files when a
>one-liner should have sufficed.
>


execute the bash command "set -x" and then check what the shell does
to $a.



Villy


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

Date: 30 Jul 2003 15:03:07 +0200
From: Francois Wisard <zebuwin@yahoo.fr>
Subject: Re: weird "perl -e" behaviour
Message-Id: <slrnbifggb.n5.zebuwin@pingou.bluewin.ch>

On 30 Jul 2003 12:46:16 GMT, Villy Kruse wrote:
> execute the bash command "set -x" and then check what the shell does
> to $a.

Oh, thanks :)

On Linux bash didn't interpret the $ vars...

Francois


-- 
The Magic of Windows: Turns a 486 back into a PC/XT. 


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

Date: Wed, 30 Jul 2003 14:23:16 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Win32 Ole
Message-Id: <3F27D561.23493425@earthlink.net>


Hans-Peter Pohl wrote:

> Hi,
>
> I compared with some Excel automation scripts I did in the past.
> I do not know why yours in not working, but please try the following
> (I tried to incorporate your example)...
> ______________________
> snip
> _________________________
>
> With me, this works fine.
> The data you type in, will be in cells B1, B2 ,..;
> A1 contains foo and
> A8..C9 the array.
>
> The output is as expected:
> <undef>|Xyzzy|Plugh|
> 42|Perl|3.1415|
>
> As you see, I use OLE, not Win32::OLE (never tried).
>
> HTH and good luck
> Hans-Peter Pohl

I haven't tried your script yet, but plan to soon.  First I thought
I would respond to your questions.  This may make me look
like an idiot, but here goes.

I put OLE.pm  under  C:\Perl\lib\Win32
I had to create the Win32 folder.  The OLE.pm file has
"package Win32::OLE;" at the top of other code..

My Excel.pm script from the example has:
"use Win32::OLE;", along with all the other code I posted in
my first post.  I put a bunch of "my"s in there to get it to
pass the strict call.

I'm guessing all this is OK (except maybe my "my"s), but
I'm wondering if the OLE.pm is named right and put in the
right place.

I'll go get OLE right now and try your script.


Thanks for the response.


Mike







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

Date: Wed, 30 Jul 2003 14:38:48 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Win32 Ole
Message-Id: <3F27D905.FE37E465@earthlink.net>


Bart Lateur wrote:

> Mike Flannigan wrote:
>
> It seems to me like your script may be fine, but this really sounds like
> a here-doc problem in the module. How did you install it?

I put OLE.pm  under  C:\Perl\lib\Win32
I had to create the Win32 folder.

My Excel.pl script is in:   C:\Perl\00MikeF
and I run it from there.


> On my system, line 29 reads
>
>                     eval <<'OVERLOAD';
>

That is interesting.  "eval <<'OVERLOAD';" is on line 57 in my
pm file.  Even if I ignore all the blank lines, it would be on line
23, or somewhere around there.


> The equivalent end delimiter is on line 33... It should just be the word
> "OVERLOAD" on its own line, with no additional whitespace around it,
> whatsoever. I think that is not the case.

Thanks.  I believe that is the case.  At least that's the way it
appears in Notepad.

Here is part of the code in that area, blank lines and all:

sub export_fail {

    shift;

    my @unknown;

    while (@_) {

 my $symbol = shift;

 if ($symbol eq 'OVERLOAD') {

     eval <<'OVERLOAD';

         use overload '""'     => \&valof,

                      '0+'     => \&valof,

                      fallback => 1;

OVERLOAD

 }

 elsif ($symbol eq 'EVENTS') {

     Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE());

 }

 else {

     push @unknown, $symbol;

 }

    }

    return @unknown;

}



> So: how did you install it?
>
> (p.s. And what's up with the case, with you? It's "Win32::OLE", not
> "Win32::Ole", and that word is "OVERLOAD3, not "Overload".)

Right you are.  My mistake.  It is OLE everywhere I can see,
except in my subject line and in "sub OleQuit {".




>





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

Date: Wed, 30 Jul 2003 13:07:42 +0000
From: Rich <scriptyrich@yahoo.co.uk>
Subject: Re: zero but true?
Message-Id: <bg8cbm$dd9$1@news6.svr.pol.co.uk>

Gregory Toomey wrote:

> "bill" <bill_knight2@yahoo.com> wrote in message
> news:bg6i4s$p8m$1@reader1.panix.com...
>>
>>
>> $ perl -e 'print "$]: ", 0E0 ? "OK\n" : "not OK\n"'
>> 5.008: not OK
>>
>> Isn't 0E0 supposed to evaluate to true?
>>
> 
> When does  0 evaluate to true in Boolean logic?
> 
> If you expect 0 to evaluate to true, do you expect 1 to evaluate to false?
> 
> gtoomey

Well I dunno why you're being so sarcastic about this:

perldoc DBI, for example:

  "For a non-"SELECT" statement, "execute" returns the number of rows
  affected, if known. If no rows were affected, then "execute"
  returns "0E0", which Perl will treat as 0 but will regard as true."
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

So, as another poster mentioned, it should be "0E0":

  perl -e 'print "$]: ", "0E0" ? "OK\n" : "not OK\n"'
  5.008: OK

An easy mistake to make, as I know from experience, and one that at least
deserves a sensible reply IMHO.

Cheers,
-- 
Rich
scriptyrich@yahoo.co.uk


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

Date: 30 Jul 2003 12:51:57 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: zero but true?
Message-Id: <slrnbiffrd.hh.vek@station02.ohout.pharmapartners.nl>

On Wed, 30 Jul 2003 13:07:42 +0000,
    Rich <scriptyrich@yahoo.co.uk> wrote:


>Gregory Toomey wrote:
>
>> "bill" <bill_knight2@yahoo.com> wrote in message
>> news:bg6i4s$p8m$1@reader1.panix.com...
>>>
>>>
>>> $ perl -e 'print "$]: ", 0E0 ? "OK\n" : "not OK\n"'
>>> 5.008: not OK
>>>
>>> Isn't 0E0 supposed to evaluate to true?
>>>
>> 
>> When does  0 evaluate to true in Boolean logic?
>> 
>> If you expect 0 to evaluate to true, do you expect 1 to evaluate to false?
>> 
>> gtoomey
>
>Well I dunno why you're being so sarcastic about this:
>
>perldoc DBI, for example:
>
>  "For a non-"SELECT" statement, "execute" returns the number of rows
>  affected, if known. If no rows were affected, then "execute"
>  returns "0E0", which Perl will treat as 0 but will regard as true."
>  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>So, as another poster mentioned, it should be "0E0":
>
>  perl -e 'print "$]: ", "0E0" ? "OK\n" : "not OK\n"'
>  5.008: OK
>
>An easy mistake to make, as I know from experience, and one that at least
>deserves a sensible reply IMHO.
>


Wheter 0e0 or 0E0 is a zero may depend on the perl version.  My old version
complains that 0E0 is a bareword, and thus not a zero.  0.E0 is zero though.


$ echo 'print "OK" unless 0E0;' | perl -w
Bareword found where operator expected at - line 1, near "0E0"
	(Missing operator before E0?)
syntax error at - line 1, near "0E0"
Execution of - aborted due to compilation errors.
$ echo 'print "OK" unless 0.E0;' | perl -w
OK



Villy


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.  

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 V10 Issue 5292
***************************************


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