[23362] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5581 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 29 00:06:05 2003

Date: Sun, 28 Sep 2003 21:05:10 -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           Sun, 28 Sep 2003     Volume: 10 Number: 5581

Today's topics:
    Re: A couple of hash questions <nospam_for_jkeen@concentric.net>
    Re: A couple of hash questions <noreply@gunnar.cc>
    Re: A couple of hash questions <dave.nospam@ntlworld.com>
    Re: A couple of hash questions (Grendel)
    Re: A couple of hash questions <penny1482@comcast.net>
    Re: A couple of hash questions <minceme@start.no>
    Re: add half an hour to all times in file <krahnj@acm.org>
    Re: add half an hour to all times in file <invalid-email@rochester.rr.com>
    Re: add half an hour to all times in file <invalid-email@rochester.rr.com>
        Am I on the right track - timezones (Jon)
    Re: Am I on the right track - timezones <nospam_for_jkeen@concentric.net>
        Convert perl structure (Tree::Nary) to scalar <ppagee@yahoo.com>
    Re: Convert perl structure (Tree::Nary) to scalar <ppagee@yahoo.com>
    Re: Determine connection status on Linux <kalinaubears@iinet.net.au>
        Hiding PERL code <1443131@usenetplanet.com>
    Re: Hiding PERL code <nospam_for_jkeen@concentric.net>
    Re: Hiding PERL code (Tad McClellan)
    Re: Hiding PERL code <invalid-email@rochester.rr.com>
    Re: How exactly do I build %INC keys? <kevin@vaildc.net>
    Re: How exactly do I build %INC keys? <nospam_for_jkeen@concentric.net>
    Re: How exactly do I build %INC keys? <noemail@rochester.rr.com>
    Re: How exactly do I build %INC keys? <tcurrey@no.no.i.said.no>
        newbie very basic question (fabre)
    Re: newbie very basic question <kalinaubears@iinet.net.au>
        Perl Help - Windows Perl script accessing a Unix perl S <dpackwood@earthlink.net>
    Re: perl makefile.pl --help <lev@serebryakov.spb.ru>
        Printing every element of an array <shemond@hotmail.com>
    Re: Printing every element of an array <nospam_for_jkeen@concentric.net>
    Re: Printing every element of an array (Tad McClellan)
    Re: Printing every element of an array <invalid-email@rochester.rr.com>
    Re: Splitting subroutines out of a file <nospam_for_jkeen@concentric.net>
        Strange `Storable' behavior <lev@serebryakov.spb.ru>
    Re: Strings, pattern matching (Tad McClellan)
    Re: use strict with an undeclared variable (ko)
    Re: use strict with an undeclared variable <grazz@pobox.com>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 28 Sep 2003 18:17:36 GMT
From: "James E Keenan" <nospam_for_jkeen@concentric.net>
Subject: Re: A couple of hash questions
Message-Id: <bl78k0$ckg@dispatch.concentric.net>


"Dave Saville" <dave.nospam@ntlworld.com> wrote in message
news:qnirfnivyyragyjbeyqpbz.hly1oo2.pminews@text.news.ntlworld.com...
> If I have a complicated structure, say a hash of hashes/arrays etc and
> I want to save it for later I can use store().
>
> If I only have a simple hash, just plain name/value pairs, then is it
> more efficient to use store() or a plain text file? Taking into account
> reading the thing back in.
>

The answer probably depends on your definition of "efficient":  fastest?
smallest memory footprint?  It also probably depends on the size of the hash
you're manipulating.

If it's a question of speed, the answer is probably best determined thru
benchmarking.  (perldoc Benchmark)

> If the latter, is there a better way to read it back in, assuming space
> separated one pair/line, than:
>
> ($name, $value) = split;
> $hash{$name} = $value;
>
Probably as good as you will get.




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

Date: Sun, 28 Sep 2003 20:29:52 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: A couple of hash questions
Message-Id: <bl79jf$8hmlp$1@ID-184292.news.uni-berlin.de>

Dave Saville wrote:
> If I only have a simple hash, just plain name/value pairs, then is
> it more efficient to use store() or a plain text file? Taking into
> account reading the thing back in.

Your direct question was commented on by James.

Have you considered using DBM files?

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



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

Date: Sun, 28 Sep 2003 20:21:15 +0100 (BST)
From: "Dave Saville" <dave.nospam@ntlworld.com>
Subject: Re: A couple of hash questions
Message-Id: <qnirfnivyyragyjbeyqpbz.hly8zf3.pminews@text.news.ntlworld.com>

On Sun, 28 Sep 2003 20:29:52 +0200, Gunnar Hjalmarsson wrote:

>Dave Saville wrote:
>> If I only have a simple hash, just plain name/value pairs, then is
>> it more efficient to use store() or a plain text file? Taking into
>> account reading the thing back in.
>
>Your direct question was commented on by James.
>
>Have you considered using DBM files?

For what I am trying to do that would be overkill - Thanks for the
suggestion.

Regards

Dave Saville

NB switch saville for nospam in address




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

Date: 28 Sep 2003 20:42:28 GMT
From: grendel@-REMOVENOSPAM-durge.org (Grendel)
Subject: Re: A couple of hash questions
Message-Id: <slrnbnehs8.5tj.grendel@jalfrezi.digitaltrickery.com>

In article <qnirfnivyyragyjbeyqpbz.hly1oo2.pminews@text.news.ntlworld.com>,
Dave Saville wrote:

> If the latter, is there a better way to read it back in, assuming space
> separated one pair/line, than:
> 
> ($name, $value) = split;
> $hash{$name} = $value;

That'll work, and if you're doing something that doesn't warrant a DBM
file or such, I'll guess that the speed of how you're reading in a flat
file won't matter either.

You could do something with map, on the other hand, if you've already
got all the delimited data in an array somehow and you know there won't
by any empty values..

%hash = map { split(':',$_) } @data;



-- 
| grendel at durge dot org | web technologist | london, uk
| "It's people like you what cause unrest"


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

Date: Sun, 28 Sep 2003 17:31:15 -0700
From: "Dick Penny" <penny1482@comcast.net>
Subject: Re: A couple of hash questions
Message-Id: <SQednchO6-DD4OqiXTWJjw@comcast.com>


"Dave Saville" <dave.nospam@ntlworld.com> wrote in message
news:qnirfnivyyragyjbeyqpbz.hly1oo2.pminews@text.news.ntlworld.com...
> If I have a complicated structure, say a hash of hashes/arrays etc and
> I want to save it for later I can use store().
>
I'm no guru, but I believe I saw in this posting (2-6 months ago) the same
type of Q, and it was answered by one of the gurus to the effect of use
data:dumper (or is it dump:data) and print the thing to a file,
sort of  like print FILE, data:dump($hash ref); [or whatever the darn syntax
should be]

You can see my Perl is far from perfect, but the idea seemed good. I never
tried it, nor do I remember how to get it back.

HTH
Dick Pennt





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

Date: Mon, 29 Sep 2003 01:23:18 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: A couple of hash questions
Message-Id: <bl81i6$96s$1@troll.powertech.no>

On the CCLXXII'nd day of the MMIII'rd year, Dave Saville spoketh:

> If I have a complicated structure, say a hash of hashes/arrays etc and
> I want to save it for later I can use store().

Yes. There are a number of modules you could use for this, including
Storable and Data::Dumper. Attribute::Persistent is a cool one you
might want to check. You could store it in a database with MLDBM.

> If I only have a simple hash, just plain name/value pairs, then is it
> more efficient to use store() or a plain text file? Taking into account
> reading the thing back in.

The difference in speed probably is insignificant unless you have
a lot of data. But don't take my word for it, check for yourself. If
you wonder about performance of different methods, it's time to
learn how to use the Benchmark module. The pods contains examples,
and the module is easy to use.  

> If the latter, is there a better way to read it back in, assuming space
> separated one pair/line, than:
>
> ($name, $value) = split;
> $hash{$name} = $value;

split() is fine. Another way is using a capturing regex. If the data
is in fixed-width columns you could use unpack() or substr().

-- 
                                                  (,_    ,_,    _,)
                                                  /|\`\._( )_./'/|\
                                                 · ·  \/ L /\ D  · ·
                                                /__|.-'`-\_/-`'-.|__\
`·..·´¯`·..·´¯`·..·´¯`·..·´¯`·..·´¯`·..·´¯`·.. `          "          `


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

Date: Sun, 28 Sep 2003 18:52:09 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: add half an hour to all times in file
Message-Id: <3F772DAF.17C68E05@acm.org>

Bart Lateur wrote:
> 
> Bob Walton wrote:
> 
> >Yes, I had to sacrifice my email address to the spam gods (suddenly
> >spam-bombed at the rate of 2000/day).
> 
> The Swen worm. See my little script to delete them from a POP server, by
> examinging the start of the message for a MIME subheader for an
> executable attachment.
> 
>         <http://perlmonks.org/index.pl?node_id=292982>

Ah yes, good old SWEN.  I'm just deleting anything on my POP server that
is over 50,000 bytes in size.


John
-- 
use Perl;
program
fulfillment


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

Date: Sun, 28 Sep 2003 20:28:27 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: add half an hour to all times in file
Message-Id: <3F774467.808@rochester.rr.com>

John Bokma wrote:

> Bob Walton wrote:
> 
>> Dan Jacobson wrote:
>>
>>> [Couldn't reply to Mr. Walton's spam protected address, even after
>>> decoding. See http://jidanni.org/comp/spam/ ]
>>
>>
>> Yes, I had to sacrifice my email address to the spam gods (suddenly 
>> spam-bombed at the rate of 2000/day).  And the new one's not going on 
> 
> 
> That's Swen. I am blocking it at the server at the moment.
> 
>> usenet in *any* form.  I'll be nice and change the addresses to 
>> something like totally@bogus.com (oh, oops, I see bogus.com is live) 
>> so folks don't waste their time.  Thanks for mentioning that.
> 
> 
> put .invalid at the end. Don't invent TLDs, or worse domains. Even the 
> most silly domain names might come in existence one day. And since 
> harvested email addresses end up on CD ROMs and are not checked if valid 
> it is quite possible that a new domain ends up with hundreds of spam 
> mailes a day thanks to someone "inventing" a domain name.
> 

Thanks for the information -- I have done that.

-- 
Bob Walton



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

Date: Mon, 29 Sep 2003 02:15:33 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: add half an hour to all times in file
Message-Id: <3F7795BE.60407@rochester.rr.com>

Gunnar Hjalmarsson wrote:

> John Bokma wrote:
> 
>> Bob Walton wrote:
>>
>>> Yes, I had to sacrifice my email address to the spam gods
 ...
> The link in my sig takes you to a contact form, which I have found to
> be a convenient way to still being contactable. I wrote a Perl module
> for the purpose, btw: http://search.cpan.org/~gunnar/
> 

Gunnar, thanks!  I have implemented that suggestion.

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: 28 Sep 2003 15:01:27 -0700
From: jon18_uk2002@yahoo.co.uk (Jon)
Subject: Am I on the right track - timezones
Message-Id: <83bd902f.0309281401.5293f14a@posting.google.com>

Hello,

I am trying to take a date (day/month/year) and time (hour:min) from
the user, and also a timezone which that date/time is based on.  I
then need to pull all logs out of a database which happens on that
supplied date and time.

The log stores everything by its timestamp, which I take from time(). 
So all the timestamps should be based in UTC time.  So first step I
need to do is take the supplied date/time and turn it into a UTC
timestamp.

I do that by setting the $ENV{TZ} to the timezone and then use
timegm(), I remembered to take away -1 from the month.

So I now have what I think is the UTC timestamp of the supplied
time/date.  Now here is the problem, I thought I could reverse this,
and turn that timestamp back into the original date/time (in its
timezone).

Again I set the ENV{TZ} and this time use localtime() on the
timestamp.  This would return a different date/time compared to the
original.  An example of what code I used is as follows.

$ENV{TZ} = ':/usr/share/zoneinfo/Europe/Paris';
$localseconds = timegm(27,11,10,15,8,2003);
print "$localseconds\n";

(11 minutes past 10am, and 27 seconds on the 15th August 2003)

$localseconds is 1063620687.

$ENV{TZ} = ':/usr/share/zoneinfo/Europe/Paris';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime('1063620687');

Now, it returns 12:11:27 on the 15th.  Which is 2 hours out of the
original date and time.  Have I got the functions mixed up, or am I
just not on the right track here?

Thank you in advance for any help,

Jon.


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

Date: 29 Sep 2003 02:24:22 GMT
From: "James E Keenan" <nospam_for_jkeen@concentric.net>
Subject: Re: Am I on the right track - timezones
Message-Id: <bl854m$cke@dispatch.concentric.net>


"Jon" <jon18_uk2002@yahoo.co.uk> wrote in message
news:83bd902f.0309281401.5293f14a@posting.google.com...
> Hello,
>
> I am trying to take a date (day/month/year) and time (hour:min) from
> the user, and also a timezone which that date/time is based on.  I
> then need to pull all logs out of a database which happens on that
> supplied date and time.
>
> The log stores everything by its timestamp, which I take from time().
> So all the timestamps should be based in UTC time.  So first step I
> need to do is take the supplied date/time and turn it into a UTC
> timestamp.
>

The answer can probably be found in one of the following 3 modules from
CPAN:
Date::Format
Date::Calc
Date::Manip

jimk





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

Date: Sun, 28 Sep 2003 21:11:02 +0200
From: Mike Mimic <ppagee@yahoo.com>
Subject: Convert perl structure (Tree::Nary) to scalar
Message-Id: <YmGdb.4027$2B6.691839@news.siol.net>

Hi!

How can I convert Tree::Nary structure to a scalar so
that I can save it into a column in a MySQL database.

I know Tree::Nary::Extended but it is not what I need because
it uses whole table. I would need that the structure would be
in a single column from many columns.

So I would convert it to scalar, save it into BLOB typed column
and read it later, convert it back and use it.

If there is nothing in existence I can program it. Just tell me how
(show me the way).


Mike



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

Date: Sun, 28 Sep 2003 21:20:11 +0200
From: Mike Mimic <ppagee@yahoo.com>
Subject: Re: Convert perl structure (Tree::Nary) to scalar
Message-Id: <yvGdb.4028$2B6.691726@news.siol.net>

Hi!

> How can I convert Tree::Nary structure to a scalar so
> that I can save it into a column in a MySQL database.

Found Storable. I thought it is only for writing to a file.

I will give it a try.


Mike



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

Date: Mon, 29 Sep 2003 09:18:54 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Determine connection status on Linux
Message-Id: <3f776d12$0$23611$5a62ac22@freenews.iinet.net.au>

David Efflandt wrote:

> 
> #!/usr/bin/perl -w
> if (system '/sbin/ifconfig ppp0 > /dev/null 2>&1') {
>     die "we are offline\n";
> }
> print "we are online\n";
> # do something useful
> 

And if offline, how to connect ?
I didn't ask initialy because I thought I had the answer to that with:
system 'kppp -c account';
but that command, while it establishes and keeps open a connection, 
never exits. Put that in a perl script, and it never progresses beyond 
that point.
I'm not so sure that's the expected behaviour of that system command - I 
thought it *did* open the connection and exit the first time I ran it, 
but it certainly won't now.

Anyway, thanks for any help on this.
(I've asked about this on the mandrake ng but they're being a little 
slow to respond.)

Cheers,
Rob


-- 
To reply by email u have to take out the u in kalinaubears.



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

Date: Sun, 28 Sep 2003 21:54:00 -0400
From: Forte Agent <1443131@usenetplanet.com>
Subject: Hiding PERL code
Message-Id: <754fnv0g3l4ndnjck564kain08om76ineb@4ax.com>

Is there some way to hide PERL source code (maybe
encrypting/obfuscating it), so that you can distribute it without
revealing source code?  Thank you in advance.





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

Date: 29 Sep 2003 02:22:06 GMT
From: "James E Keenan" <nospam_for_jkeen@concentric.net>
Subject: Re: Hiding PERL code
Message-Id: <bl850e$ck5@dispatch.concentric.net>


"Forte Agent" <1443131@usenetplanet.com> wrote in message
news:754fnv0g3l4ndnjck564kain08om76ineb@4ax.com...
> Is there some way to hide PERL source code (maybe
> encrypting/obfuscating it), so that you can distribute it without
> revealing source code?  Thank you in advance.
>
>
>
Have you considered Acme::Bleach or Acme::Buffy from CPAN?




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

Date: Sun, 28 Sep 2003 21:16:15 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Hiding PERL code
Message-Id: <slrnbnf5ff.hrp.tadmc@magna.augustmail.com>

Forte Agent <1443131@usenetplanet.com> wrote:

> Is there some way to hide PERL source code (maybe
                       ^^^^
                       ^^^^
> encrypting/obfuscating it), so that you can distribute it without
> revealing source code?  Thank you in advance.


What happened when you typed this before posting?

   perldoc -q hide


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Mon, 29 Sep 2003 02:30:24 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Hiding PERL code
Message-Id: <3F779939.1020105@rochester.rr.com>

Forte Agent wrote:

> Is there some way to hide PERL source code (maybe
> encrypting/obfuscating it), so that you can distribute it without
> revealing source code?  Thank you in advance.

Sure.  Delete it.  Seriously, that's a FAQ:

    perldoc -q hide

For some fun with pseudo-hiding it, use Acme::Bleach; and other Acme's. 
  But note that it's still possible to get the source code back (but 
don't start by trying it on your only copy of your masterpiece).
-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Sun, 28 Sep 2003 14:14:06 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: How exactly do I build %INC keys?
Message-Id: <kevin-E8A4FC.14140628092003@news101.his.com>

In article <bl70ds$5vf$1@news7.svr.pol.co.uk>,
 Rich <scriptyrich@yahoo.co.uk> wrote:

> According to camel p.300:
> 
>   "The key will be the module filename"
> 
> I therefore tried the following to test whether Data::Dumper (for example)
> had been used:
> 
>   use File::Spec;
>   use Data::Dumper;
> 
>   my $filename = File::Spec->catfile("Data", "Dumper.pm");
> 
>   print $INC{$filename} ? "yes\n" : "no\n";        # Fails on Win32

Yup, because the catfile call yields Data\Dumper.pm.

> I know Win32 perl allows '/' as well as '\' directory separators, but now
> I'm not sure of the correct way to build %INC keys. Is it:
> 
> 1) The key is actually the same on all platforms. Ie $INC{"Data/Dumper.pm"}
>    will work on all platforms (Mac, VMS etc).

Yes.  If you have a module name in $module, then this will convert it to 
the key for %INC:

   $module =~ s{::}{/}g;
   $module .= '.pm';

(I haven't tested those two particular lines of code, but I've used the 
general principle in a couple of programs.)
-- 
Bright eyes/burning like fire,           | Kevin Michael Vail
Bright eyes/how can you close and fail?  | kevin@vaildc.net
How can the light that shone so brightly | . . . . . . . . . .
Suddenly shine so pale?/Bright eyes      |  . . . . . . . . .


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

Date: 28 Sep 2003 18:39:57 GMT
From: "James E Keenan" <nospam_for_jkeen@concentric.net>
Subject: Re: How exactly do I build %INC keys?
Message-Id: <bl79tt$ckc@dispatch.concentric.net>


"Rich" <scriptyrich@yahoo.co.uk> wrote in message
news:bl70ds$5vf$1@news7.svr.pol.co.uk...
> According to camel p.300:
>
>   "The key will be the module filename"
>
> I therefore tried the following to test whether Data::Dumper (for example)
> had been used:
>
>   use File::Spec;
>   use Data::Dumper;
>
>   my $filename = File::Spec->catfile("Data", "Dumper.pm");
>
>   print $INC{$filename} ? "yes\n" : "no\n";        # Fails on Win32
>
> But although it worked on Linux, it failed on Win32 where the key is
> actually the same as under Linux:
>
The "failure" is actually a feature of File::Spec.  File::Spec imports
routines from a system-appropriate subpackage, in this case
File::Spec::Win32, which appears to use the DOS '\' as the path separator.
If you do not need to use File::Spec to achieve your larger purpose (about
which I'm unclear), then Perl will happily use '/' throughout.




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

Date: Sun, 28 Sep 2003 18:43:02 GMT
From: Bob Walton <noemail@rochester.rr.com>
Subject: Re: How exactly do I build %INC keys?
Message-Id: <3F772BB0.9020002@rochester.rr.com>

Rich wrote:

> According to camel p.300:
> 
>   "The key will be the module filename"
> 
> I therefore tried the following to test whether Data::Dumper (for example)
> had been used:
> 
>   use File::Spec;
>   use Data::Dumper;
> 
>   my $filename = File::Spec->catfile("Data", "Dumper.pm");
> 
>   print $INC{$filename} ? "yes\n" : "no\n";        # Fails on Win32
> 
> But although it worked on Linux, it failed on Win32 where the key is
> actually the same as under Linux:
> 
>   print $INC{"Data/Dumper.pm"} ? "yes\n" : "no\n"; # OK on Win32 and Linux
> 
> I know Win32 perl allows '/' as well as '\' directory separators, but now
> I'm not sure of the correct way to build %INC keys. Is it:
> 
> 1) The key is actually the same on all platforms. Ie $INC{"Data/Dumper.pm"}
>    will work on all platforms (Mac, VMS etc).


It would appear that on Win32 %INC keys use / and File::Spec uses \ .

Try [tested on Windoze 98SE AS build 806]: 

   $filename = File::Spec::Unix->catfile("Data", "Dumper.pm");

Things work in Unix :-)

But wouldn't it be easier to just say 

   $filename='Data/Dumper.pm';

?  Also, note that %INC might contain other stuff, 

like hooks and whatever the hook may have placed there.

So it is possible there could be a surprise waiting in
%INC for you.


> 
> 2) The key must use the system directory separator - in that case, since
>    File::Spec->catfile didn't work, where is the "correct" system directory
>    separator defined? Equally, do I need to be careful with how I handle
>    ".pm" extensions?
> 
> If the answer is 2), does anyone have tested code they could post here to
> handle this?


 ...


-- 
Bob Walton



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

Date: Sun, 28 Sep 2003 20:31:29 -0700
From: "Trent Curry" <tcurrey@no.no.i.said.no>
Subject: Re: How exactly do I build %INC keys?
Message-Id: <bl8933$ki7$1@news.astound.net>

Bob Walton wrote:
> Rich wrote:
>
>> According to camel p.300:
>>
>>   "The key will be the module filename"
>>
>> I therefore tried the following to test whether Data::Dumper (for
>> example) had been used:
>>
>>   use File::Spec;
>>   use Data::Dumper;
>>
>>   my $filename = File::Spec->catfile("Data", "Dumper.pm");
>>
>>   print $INC{$filename} ? "yes\n" : "no\n";        # Fails on Win32
>>
>> But although it worked on Linux, it failed on Win32 where the key is
>> actually the same as under Linux:
>>
>>   print $INC{"Data/Dumper.pm"} ? "yes\n" : "no\n"; # OK on Win32 and
>> Linux
>>
>> I know Win32 perl allows '/' as well as '\' directory separators,
>> but now I'm not sure of the correct way to build %INC keys. Is it:
>>
>> 1) The key is actually the same on all platforms. Ie
>>    $INC{"Data/Dumper.pm"} will work on all platforms (Mac, VMS etc).
>
>
> It would appear that on Win32 %INC keys use / and File::Spec uses \ .
>
> Try [tested on Windoze 98SE AS build 806]:
>
>    $filename = File::Spec::Unix->catfile("Data", "Dumper.pm");

In the man page for File::Spec::Unix, under Synopsis, it reads:

   require File::Spec::Unix; # Done automatically by File::Spec
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Is this a bug in the Win32 version that it gives \ and not / as expected? Or
is file::Spec defaulting to the current OS Spec sub class?

-- 
Trent Curry

perl -e
'($s=qq/e29716770256864702379602c6275605/)=~s!([0-9a-f]{2})!pack("h2",$1)!eg
;print(reverse("$s")."\n");'




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

Date: Mon, 29 Sep 2003 04:25:44 +0100
From: pedro.fabre.NO-SPAM@gen.gu.se (fabre)
Subject: newbie very basic question
Message-Id: <pedro.fabre.NO-SPAM-2909030425440001@192.168.0.5>

Dear all,

I was reading perldoc perlref and I have seen an example about the use of
subroutines.


this is the code:

#!/usr/local/bin/perl -w
 
sub newprint {            
    my $x = shift;            
    print "$x\n";                                                
}            

newprint("Howdy");                 
newprint("Greetings");                 
 
two things, Howdy and Greetings are passed as values, right? but then on
the newprint, these values need to be taken somewhere. I think, they must
me taken in shift, but the function of shift is remove the first element
from a list and   pass this value out as return, but there is no list.
Where and how Howdy goes  into newprint?

I can undertand this:

#!/usr/local/bin/perl -w
 
sub newprint {               
    @var =@_;   
    my $x = shift @var;   
    print "$x\n";                                                   
}               
newprint("Howdy");                    
newprint("Greetings");                    


but is no clear to me how Howdy and Greetings go into new print.

Someone can explain this to me?

Thanks a million
Pedro


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

Date: Mon, 29 Sep 2003 13:41:02 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: newbie very basic question
Message-Id: <3f77aa82$0$23603$5a62ac22@freenews.iinet.net.au>

fabre wrote:
> Dear all,
> 
> I was reading perldoc perlref and I have seen an example about the use of
> subroutines.
> 
> 
> this is the code:
> 
> #!/usr/local/bin/perl -w
>  
> sub newprint {            
>     my $x = shift;            
>     print "$x\n";                                                
> }            
> 
> newprint("Howdy");                 
> newprint("Greetings");                 
>  
> two things, Howdy and Greetings are passed as values, right? but then on
> the newprint, these values need to be taken somewhere. I think, they must
> me taken in shift, but the function of shift is remove the first element
> from a list and   pass this value out as return, but there is no list.
> Where and how Howdy goes  into newprint?
> 
> I can undertand this:
> 
> #!/usr/local/bin/perl -w
>  
> sub newprint {               
>     @var =@_;   
>     my $x = shift @var;   
>     print "$x\n";                                                   
> }               
> newprint("Howdy");                    
> newprint("Greetings");                    
> 
> 
> but is no clear to me how Howdy and Greetings go into new print.
> 
> Someone can explain this to me?
> 
> Thanks a million
> Pedro

Try this:

my $x = newprint("Howdy");
sub newprint {
print "\@_ contains: @_\n";
my $y = shift;
print "\@_ now contains: @_\n";
print $y, "\n";
}

'shift' is actually shifting from the special array, @_, which contains 
a list of all arguments.

It shifts from @_ because no other array has been specified.

You weren't far away from working that out :-)

Hth.

Cheers,
Rob

-- 
To reply by email u have to take out the u in kalinaubears.



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

Date: Mon, 29 Sep 2003 03:05:05 GMT
From: "dpackwood" <dpackwood@earthlink.net>
Subject: Perl Help - Windows Perl script accessing a Unix perl Script
Message-Id: <BjNdb.7424$RW4.3844@newsread4.news.pas.earthlink.net>

Hello,

I have two different scripts that do pretty much the same thing. The main
perl script is on Windows. It runs and in the middle of it, it then calls
out another perl script that then should run on a Unix box I have. Both
scripts run ok, except for the part when Windows try's to call out the
Unix script. I have it set up where the Unix is mapped through a drive
letter and can drop stuff into the Unix box. It is going through another
server to do that. So I can see the script and drop files into the Unix box
but just can't figure out why perl will not call out the script. When I call
out the perl script through the command line of windows I get " specified
path not found", even though I'm in that directory.

Has any one done anything like this that would be willing to either help me
or point me in the right direction to do research on it. Thanks

-Dale




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

Date: Sun, 28 Sep 2003 14:23:14 +0400
From: Lev Serebryakov <lev@serebryakov.spb.ru>
Subject: Re: perl makefile.pl --help
Message-Id: <bl6ceb$1q2j$1@news.wplus.net>

Hello, King!

King wrote:

> what is perl makefile.pl does and why the switch --help is putting out
> $perl makefile.pl --help
> Can't open perl script "makefile.pl": No such file or directory
> $ even if I /bin/su gives the same line above.
  Normally, this file have name Makefile.PL, not makefile.pl. It seems, 
that you use so,me flavor of UNIX, so case of name is urgent.

--
    Lev A. Serebryakov



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

Date: Sun, 28 Sep 2003 21:21:54 -0400
From: Steve =?ISO-8859-1?Q?H=E9mond?= <shemond@hotmail.com>
Subject: Printing every element of an array
Message-Id: <CMLdb.3506$ab5.106674@news20.bellglobal.com>

Hi people,

This is actually a basic question ...

For each element of an array, I need to print the previous element, the
actual element, and the next element on a line.

Example :

@test = "One","Two","Three","Four","Five";

The program need to read each array element, then print its previous, actual
and next value :

Output :

*nothing*,One,Two
One, Two, Three
Two, Three, Four
Three,Four,Five

I was thinking of using a simple FOR statement :

for ($i=$array[0]; $i==$array[LAST ELEMENT]; $i++)

I know this is completely wrong. I just want to show you the logic I am
thinking about.

Any ideas ?

Thanks in advance,

Steve


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

Date: 29 Sep 2003 02:21:25 GMT
From: "James E Keenan" <nospam_for_jkeen@concentric.net>
Subject: Re: Printing every element of an array
Message-Id: <bl84v5$cki@dispatch.concentric.net>


"Steve Hémond" <shemond@hotmail.com> wrote in message
news:CMLdb.3506$ab5.106674@news20.bellglobal.com...
> Hi people,
>
> This is actually a basic question ...
>
> For each element of an array, I need to print the previous element, the
> actual element, and the next element on a line.
>
> Example :
>
> @test = "One","Two","Three","Four","Five";
>
> The program need to read each array element, then print its previous,
actual
> and next value :
>
> Output :
>
> *nothing*,One,Two
> One, Two, Three
> Two, Three, Four
> Three,Four,Five
>

Not elegant, but it works:

    my @test = qw(One Two Three Four Five);

    for (my $i=0; $i<=$#test; $i++) {
        if ($i == 0) {
            print "Nothing\t$test[$i]\t$test[$i+1]\n";
        } elsif ($i == $#test) {
            print "$test[$i-1]\t$test[$i]\tNothing\n";
        } else {
            print "$test[$i-1]\t$test[$i]\t$test[$i+1]\n";
        }
    }

jimk




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

Date: Sun, 28 Sep 2003 21:23:06 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Printing every element of an array
Message-Id: <slrnbnf5sa.hrp.tadmc@magna.augustmail.com>

Steve Hémond <shemond@hotmail.com> wrote:

> Example :
> 
> @test = "One","Two","Three","Four","Five";


That has the same effect as:

   $test[0] = 'One';
or
   @test = 'One';
or
   @test = ('One');

Please post actual code!


> The program need to read each array element, then print its previous, actual
> and next value :


--------------------------------
#!/usr/bin/perl
use strict;
use warnings;

my @test = ("One","Two","Three","Four","Five");

my $prev='*nothing*';
for my $i ( 0.. $#test ) {
    print "$prev,$test[$i],$test[$i+1]\n";
    $prev = $test[$i];
}
--------------------------------


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Mon, 29 Sep 2003 02:49:18 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Printing every element of an array
Message-Id: <3F779DA6.9030604@rochester.rr.com>

Steve Hémond wrote:

 ...
> For each element of an array, I need to print the previous element, the
> actual element, and the next element on a line.
> 
> Example :
> 
> @test = "One","Two","Three","Four","Five";

---------^---------------------------------^---need =(....);


> 
> The program need to read each array element, then print its previous, actual
> and next value :
> 
> Output :
> 
> *nothing*,One,Two
> One, Two, Three
> Two, Three, Four
> Three,Four,Five
> 
> I was thinking of using a simple FOR statement :
> 
> for ($i=$array[0]; $i==$array[LAST ELEMENT]; $i++)
> 
> I know this is completely wrong. I just want to show you the logic I am
> thinking about.
> 
> Any ideas ?
 ...


> Steve

Maybe something like:

@test =("One","Two","Three","Four","Five");
print join(',',('*nothing*',@test,'*nothing*')
    [$_..$_+2])."\n" for 0..$#test;

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: 29 Sep 2003 01:39:08 GMT
From: "James E Keenan" <nospam_for_jkeen@concentric.net>
Subject: Re: Splitting subroutines out of a file
Message-Id: <bl82fs$ckg@dispatch.concentric.net>


"Bob Walton" <noemail@rochester.rr.com> wrote in message
news:3F7701F3.3070905@rochester.rr.com...
> Jos De Laender wrote:
>
>
> My approach would be to manually examine the source in an editor and
> insert a special flag between subs (something like a line consisting of:
>
> #~~sub~~
>
> -- anything that won't otherwise appear in the code.  Then process the
> file with that as the input record separator.  You will have to decide
> how to name the files, since there might be duplicate sub names between
> files and perhaps between packages in one file (and perhaps anonymous
> subs too?) -- use a sequence number?
>
> But all in all, I don't grok what doing all that would buy you over
> simply manipulating the code into the files you want using an editor --
> it looks like that's what you're going to end up doing anyway.
>
> --
Jos:  I think Bob is right on the money here.




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

Date: Sun, 28 Sep 2003 00:38:08 +0400
From: Lev Serebryakov <lev@serebryakov.spb.ru>
Subject: Strange `Storable' behavior
Message-Id: <bl4s3h$158$1@news.wplus.net>

Hello, perl hackers!

   I write script, whcih process some data step-by-step. Each step takes 
some time (typical time is from 1 to 10 minutes, depends on input data) 
and each step could fail.
   I store full state of processing after each step with `Storable' 
module. Full state is describing by array of references: some references 
to array and some references to hashes. After first step only first 
array is not empty (it contains parsed input data), after second step 
some data is in some hashes, etc.
   I see very strange timings of Storable::store() function calls. After 
first 3 steps it is small (about 10 seconds for very big amount of input 
data), after 4th step it is very big (about 240 seconds for same input 
data), and after 5th step it is small again (12-14 seconds).
   But each step only ADDS data tosaved state. So, every next dump is 
GREATER in size that previous. And results of 4th step PRESENTS in 
results of step 5. But results of 4th step are saved 20 times longer!
   What does it mean and how this could be fixed?

   I use Activestate's perl 5.8.0 on Win2K Pro.

--
    Lev Serebryakov



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

Date: Sun, 28 Sep 2003 17:04:10 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Strings, pattern matching
Message-Id: <slrnbnemmq.glk.tadmc@magna.augustmail.com>

MJS <tabletdesktop@yahoo.com> wrote:

> I have a hard time matching and replacing this pattern. It works fine
> for single line but when I want to replace multiple line pattern, it
> doesn't seem to work. 


You must arrange to _have_ a multiline string if you want a
multiline pattern to match the string.


> I spend a lot of time on faq 


Which FAQ?

Hopefully it was this one:

   I'm having trouble matching over more than one line.  What's wrong?


> but I guess I m not
> smart enough to figure out where I am going wrong. I couldn't do it
> using the regular exp. so I tried doing it using Tie::File.


Tie::File is not an alternative to regexes.

Tie::File is an alternative to <input>.


> Please help me with this.


The first sentence of the FAQ answer points out your problem:

   Either you don't have more than one line in the string you're looking
   at (probably)
   ...
   There are many ways to get multiline data into a string
   ...


> tie my @array, 'Tie::File', 'result.txt' or die "Cannot open


Tie::File puts *one* line per array element.


> while(<result.txt>){


The <input> operator puts *one* line into $_.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 28 Sep 2003 15:16:58 -0700
From: kuujinbo@hotmail.com (ko)
Subject: Re: use strict with an undeclared variable
Message-Id: <92d64088.0309281416.75661b0f@posting.google.com>

"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message news:<Xns94046084E4DF0sdn.comcast@206.127.4.25>...
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
> 
> ko <kuujinbo@hotmail.com> wrote in
> news:bl6lms$hse$1@pin3.tky.plala.or.jp: 
> 
> > Greg Bacon wrote:
> > 
> >> In article <bl6ge0$bra$1@pin3.tky.plala.or.jp>,
> >>     ko  <kuujinbo@hotmail.com> wrote:
> >> 
> >> : [...]
> >> :
> >> : 1. If you're including the strict and warnings pragmas, why is it
> >> : that you can get away with not declaring $a? [...]
> >> 
> >> The strict pragma's manpage says
> >> 
> >>     Because of their special use by sort(), the variables
> >>     $a and $b are exempted from this check.
> > 
> > Sorry, I must be missing something obvious. I don't see where sort()
> > is being called. I thought that a strict comparison is being done and
> > the whole point was to avoid using sort.
> 
> Because there exists such a thing as 'sort' (and because of how 'sort' 
> works in Perl), the variables $a and $b are exempted from this check.
> 
> - -- 
> Eric

Sometimes I need literal explanations :( Is it correct to say that $a
and $b are only exempt inside a condition and loop? For example, you
must declare $a or $b just like any other variable when used in the
main body of a program/sub:

[SNIPPET]
#!/usr/bin/perl -w
use strict;
$a = 1;

[RESULT]
Name "main::a" used only once: possible typo at f:\perl\a.pl line 3.

Thanks for bearing with me...


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

Date: Sun, 28 Sep 2003 23:11:11 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: use strict with an undeclared variable
Message-Id: <jUJdb.10991$yU5.742@nwrdny01.gnilink.net>

ko <kuujinbo@hotmail.com> wrote:
> "Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote:
> > Because there exists such a thing as 'sort' (and because of how 'sort' 
> > works in Perl), the variables $a and $b are exempted from this check.
> 
> Sometimes I need literal explanations :( Is it correct to say that $a
> and $b are only exempt inside a condition and loop?

No.  They're always exempt.  (Try it and see.)

> For example, you
> must declare $a or $b just like any other variable when used in the
> main body of a program/sub:
> 
> [SNIPPET]
> #!/usr/bin/perl -w
> use strict;
> $a = 1;
> 
> [RESULT]
> Name "main::a" used only once: possible typo at f:\perl\a.pl line 3.

That's different.  The "used only once" warning has nothing to do 
with strict.  If $a weren't exempt from strict-checking, you'd get
a compilation error.  (Try it with $c.)

-- 
Steve


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

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


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