[18183] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 351 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 24 21:07:34 2001

Date: Sat, 24 Feb 2001 18:05:14 -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: <983066713-v10-i351@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 24 Feb 2001     Volume: 10 Number: 351

Today's topics:
        2 keys for one hash. <g9karkav@cdf.toronto.edu>
    Re: 2 keys for one hash. (Steven Smolinski)
    Re: about software installation on Solaris (Michael Wang)
    Re: Can I use Excel as a data source <ron@savage.net.au>
        Delete ("y_jim Y")
        Delete ("y_jim Y")
    Re: How can I detect if program is run by cron? (Alan Barclay)
    Re: Linux Planet Example not working. Anyone got it to  (Gwyn Judd)
    Re: passing filehandles/filenames between Perl scripts <bwalton@rochester.rr.com>
    Re: passing filehandles/filenames between Perl scripts <nospam@bml.uk-mart.co.uk>
        Perl and Frames <ejmeyer@concentric.net>
    Re: Perl and Frames <no@spam.net>
    Re: Perl and Frames <flavell@mail.cern.ch>
    Re: Perl parser <bart.lateur@skynet.be>
    Re: Perl Threads -- advice needed (Ilya Zakharevich)
    Re: Perl Threads -- advice needed <dan@tuatha.sidhe.org>
    Re: regex help needed <krahnj@acm.org>
    Re: splice question <c_clarkson@hotmail.com>
    Re: splice question <jdpepin@optonline.net>
    Re: Substitute on filehandle (Garry Williams)
        time() in GMT Seconds. <gknitz@NitzSpace.com>
    Re: time() in GMT Seconds. <beable@my-deja.com>
    Re: Variable Cross Reference Listing <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 25 Feb 2001 01:03:23 GMT
From: "Kauser Ali Karim ;)" <g9karkav@cdf.toronto.edu>
Subject: 2 keys for one hash.
Message-Id: <Pine.GSO.4.30.0102241956370.9219-100000@eddie.cdf>


Hi,

Is it possible to have a hash that has two key values.
If so, I'd appreciate an example.

Thanks.

Kauser
------



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

Date: Sun, 25 Feb 2001 01:45:16 GMT
From: sjs@linux.ca (Steven Smolinski)
Subject: Re: 2 keys for one hash.
Message-Id: <slrn99gtea.1ts.sjs@ragnar.stevens.gulch>

Kauser Ali Karim ;) <g9karkav@cdf.toronto.edu> wrote:
> Is it possible to have a hash that has two key values.

Strictly speaking, no.  But the the value of a hash element can be a
reference to another hash.  This can simulate a two-keyed hash.

> If so, I'd appreciate an example.

This is actually pretty common.  See the perllol and perlref manpages
for the concepts.

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

my %salary = ( Smith => { Bob  => 30_000,
                          Ed   => 40_000,
                          Mary => 80_000 },
               Doe   => { John => 45_000,
                          Jane => 43_000 }
             );

print $salary{Smith}{Bob}, "\n";
__END__

Steve
-- 
Steven Smolinski => http://www.steven.cx/


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

Date: Sun, 25 Feb 2001 01:37:36 GMT
From: mwang@mindspring.com (Michael Wang)
Subject: Re: about software installation on Solaris
Message-Id: <AlZl6.7660$JK2.582419@news.uswest.net>

>> >Extra software you install (on any SVR4 unix) should go in /opt - that's
>> >exactly what it's for. You should make sure /opt is a separate filesystem
>> >with enough space free for all the extra unbundled software you want to
>> >add to the system.

I do know /opt, but I find it troublesome to have
/opt/this and /opt/that, and the PATH becomes ridiculously
long and unmanageable. 

/usr/local area is nice except name clashes.

I also find the Perl module installation approach is troublesome.
They always want to append something to a common file. This is hard to
make a Solaris package for the module (imagine how to add and remove).
They should just use their own files for each module, and then a program
(something like catman) to rebuild the common file any at time.


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

Date: Sun, 25 Feb 2001 12:20:53 +1100
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: Can I use Excel as a data source
Message-Id: <efYl6.5164$v4.217046@ozemail.com.au>

> cpan has a Spreadsheet::ParseExcel module... try that...

Alternately, see this:

Tutorial # 6: Using Win32::OLE to extract a range from an MS Excel file:
ole-xl-demo-1.pl

here:

http://savage.net.au/Perl-tutorials.html#tut-6

--
Cheers
Ron  Savage
ron@savage.net.au
http://savage.net.au/index.html






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

Date: 25 Feb 2001 02:08:11 +0100
From: y_jim54@hotmail.com ("y_jim Y")
Subject: Delete
Message-Id: <F148sn9BcRUVxP06dNJ00016b58@hotmail.com>

Hi,

In perl how do I in a text:
1)delete from the first word on?.
2)delete after the first word on?.
3)delete after the second word on?.

J
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com


-- 
Posted from [192.31.106.35] by way of f148.law11.hotmail.com [64.4.17.148] 
via Mailgate.ORG Server - http://www.Mailgate.ORG


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

Date: 25 Feb 2001 02:08:40 +0100
From: y_jim54@hotmail.com ("y_jim Y")
Subject: Delete
Message-Id: <F2300SpAzdgoMAmb9Cr00009fdc@hotmail.com>

Hi,

In perl how do I in a text:
1)delete from the first word on?.
2)delete after the first word on?.
3)delete after the second word on?.

y_jim54@hotmail.com
J
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com


-- 
Posted from [192.31.106.35] by way of f230.law11.hotmail.com [64.4.17.230] 
via Mailgate.ORG Server - http://www.Mailgate.ORG


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

Date: 25 Feb 2001 00:51:30 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: How can I detect if program is run by cron?
Message-Id: <983062291.552983@elaine.furryape.com>

In article <974kv4$qui$1@boomer.cs.utexas.edu>,
Logan Shaw <logan@cs.utexas.edu> wrote:
>>Easy enough to test (log the whole %ENV).
>
>Yes, easy to test.
>
>	$ echo 'env > foo' | batch

at & batch behave differently from jobs started from crontab's.

As you say, in your test case, the enviroment is read in and
used to initialize the job's enviroment.

However, jobs run from crontab do not have this step, and therefore
won't have any variables setup.

What is the original poster's definition of 'running under cron'?


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

Date: Sun, 25 Feb 2001 01:42:41 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Linux Planet Example not working. Anyone got it to work?
Message-Id: <slrn99gooe.936.tjla@thislove.dyndns.org>

I was shocked! How could Chile <abcd@ntlworld.com>
say such a terrible thing:
>Hi,
>
>I just tried out Linux planets tutorial at
>
>http://www.linuxplanet.com/linuxplanet/tutorials/1046/1/
>
>and successfully completed the setting up of db etc.. but when i run the
>script given below i get this error:

>In order to get the script to work i had to remove the -Tw after
>#!/usr/bin/perl as it gave errors and i had to take out use strict; as it
>also gave errors. so i don't know if this is causing the problem.
>
>if anyone knows how to get this working it would be great

I recommend that the first thing you do is figure out what the '-T',
'-w' switches and the 'strict' pragma actually do. Once you have done
that you will realise that they are actually pretty good things and you
should probably leave them in:

perldoc perlrun
perldoc -f strict

This does mean that you will need to understand what they are attempting
to do in order to fix the program errors that are causing them to
complain.

>     $dbh = DBI->connect("DBI:mysql:database=$server
>Db;host=$serverName;port=$serverPort",$serverUser,$serverPass);

>     $success = $dbh->do("INSERT INTO
>               $serverTabl(name,age,email,website,comments,time)
>               VALUES(?,?,?,?,?,?)", undef, $name, $age, $email, $website,

What we do here is create a database handle $dbh with the 'connect' call
and then use its 'do' method to do an INSERT. But the funny thing is
that the code above never checks to see if the 'connect' was successful.
This is bad practics in general, more so in a tutorial so maybe you
should reconsider if you want to try and learn from this example.

Anyway the first line should be something like:

 $dbh = DBI->connect(
    "DBI:mysql:database=$serverDb;host=$serverName;port=$serverPort"
    ,$serverUser,$serverPass)
        || die DBI::errstr;

This will tell you why the connect call is failing.

And the second line should have a similar error check.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
A sine curve goes off to infinity, or at least the end of the blackboard.
		-- Prof. Steiner


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

Date: Sat, 24 Feb 2001 23:11:30 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: passing filehandles/filenames between Perl scripts
Message-Id: <3A98400D.925DCC57@rochester.rr.com>

Dan Shedd wrote:
> 
> I have an application to allow a user to upload photos to a server and at the same time post data about that picture to a database.  He/she fills out a form (HTML), which then calls a perl script.  This first script generates an HTML page to allow the user to confirm his/her entries prior to posting the data to the database.  If accepted, the action for this generated HTML page is to call a second perl script which will upload the file and post the description to an Access file vie Win32:oDBC.
> My problem occurs when transferring the filename between the two scripts.  WHile the 'name' carries over, for some reason the read statement doesn't work.  Put the file upload code in the first perl script and it workds fine.  So I was wondering that is getting lost betwene the two scripts.
> 
> Below is a sample of what I am trying to do;
> 
 ...
> one.pl:
> 
> use CGI 'param'; # use CGI parameter to get dynamic info
> $filename = param('filename');
> print "<form enctype=\"multipart/form-data\" action = \"three.pl\"
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>^^^^^^^^
> method = \"post\">\n";
> print "<input type = \"hidden\" name = \"filename\" value =
> \"$filename\">\n";
> print "<input type = \"submit\">\n";
> print "</form>";
> print "</p>\n";
> 
> two.pl:
 ...
> dan
 ...
Could it be because file one.pl specifies that its action will be
carried out by a program called three.pl, rather than the two.pl program
that you show?
-- 
Bob Walton


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

Date: Sat, 24 Feb 2001 23:13:21 -0000
From: "Mark Longhurst" <nospam@bml.uk-mart.co.uk>
Subject: Re: passing filehandles/filenames between Perl scripts
Message-Id: <odXl6.15860$Zs3.93450@news11-gui.server.ntli.net>


"Dan Shedd" <donotreply@interbulletin.bogus> wrote in message
news:3A97FD8D.6F23FDE5@interbulletin.com...
> I have an application to allow a user to upload photos to a server and at
the same time post data about that picture to a database.  He/she fills out
a form (HTML), which then calls a perl script.  This first script generates
an HTML page to allow the user to confirm his/her entries prior to posting
the data to the database.  If accepted, the action for this generated HTML
page is to call a second perl script which will upload the file and post the
description to an Access file vie Win32:oDBC.
> My problem occurs when transferring the filename between the two scripts.
WHile the 'name' carries over, for some reason the read statement doesn't
work.  Put the file upload code in the first perl script and it workds fine.
So I was wondering that is getting lost betwene the two scripts.
>
> Below is a sample of what I am trying to do;
>
> first html doc;
> <HTML>
> <HEAD>
> <title>Upload File</title>
> </HEAD>
> <BODY>
> <H1><CENTER>Please Upload Your Data Files</CENTER></H1>
>
> <FORM enctype="multipart/form-data" ACTION="one.pl" METHOD="POST">
> <TABLE BORDER=0 WIDTH="100%">
> <TR>
> <TD>
> Data filename:
> </TD>
> <TD>
> <INPUT TYPE="FILE" NAME="filename" SIZE="35">
> </TD>
> </TR>
> <TR>
> <TD>
> <INPUT TYPE="SUBMIT" VALUE="Upload File">
> </TD>
> <TD ALIGN=RIGHT>
> <INPUT TYPE="RESET" VALUE="Reset">
> </TD>
> </TR>
> </TABLE>
> </FORM>
>
> </body>
> </html>
>
> one.pl:
>
> use CGI 'param'; # use CGI parameter to get dynamic info
> $filename = param('filename');
> print "<form enctype=\"multipart/form-data\" action = \"three.pl\"
> method = \"post\">\n";
> print "<input type = \"hidden\" name = \"filename\" value =
> \"$filename\">\n";
> print "<input type = \"submit\">\n";
> print "</form>";
> print "</p>\n";
>
>
>
> two.pl:
>
> use CGI 'param'; # use CGI parameter to get dynamic info
> $filename = param('filename');
> &head;
> #####
>
> #prepare to transfer picture file to server
> $DestinationDir = "c:/inetpub/wwwroot/db_dir/pictures"; # no trailing
> slash please
> $filename =~ m/^.*(\\|\/)(.*)/; # remove the path string
> $file = $2;
>
> # read in the file
> open(OUTFILE,">$DestinationDir\/$file");
> binmode OUTFILE; # binmode is for windows only. Ignored by unix
> while ($bytesread = read($filename,$buffer,1024)) {
> print OUTFILE $buffer;
> $fsize += $bytesread; # $fsize will return the size of the file
> uploaded in bytes
>  }
> close (OUTFILE);
>
> #####
> appreciate any explanation as to why filename doesn't convey thru this
> transaction
>
> tia
> dan

The problem is that you are calling the filename in the second script from a
hidden field in the form, which just plain won't work :-(

I'm not sure if this is some sort of deliberate security fix, but it would
cause a huge security hole if you could do it.  Consider what would happen
if you put the following in a Web page:

<input type="hidden" value="c:\windows\user.dat">

If this actually worked, you would get the user.dat file (which is a major
part of the Win9x Registry) uploaded to your server everytime someone
submitted the form, which would be VERY bad!  Also, this would be the same
for any other file you already know to exist on the target machine.

Anyway, as a result, the ONLY way to get a file upload to work is to use a
file upload field, which will not let you specify a default value (again I
assume a deliberate security fix).  In truth, you can specify a default
value, but it is ignored and the field comes up blank.

About the only compromise I can think of is to upload the file with the
first script, then ask if it's correct and, if not, use an unlink command to
delete it from the server.  Clumsy, I know, but it's all I can think of at
present.

You might also want to instigate a check to make sure what is being uploaded
is an actual image file (at least check the file extension) to stop anyone
uploading an exploit program/script then running it from your site (a common
trick used by crackers to diguise where they are actually attacking from).

Sorry to be the bearer of bad tidings, but that's the way it is :-(

Mark




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

Date: 25 Feb 2001 00:52:33 GMT
From: "Edward Meyer" <ejmeyer@concentric.net>
Subject: Perl and Frames
Message-Id: <979l0h$rd1@dispatch.concentric.net>

I am trying to reload multiple frames in 1 CGI script I have tried the
"Window-target:" HTTP header but can not get it to work.  The following it
the output of my script.  It does appear to work for netscape but not IE5.
Is there something I can use for IE5?

Window-target: _top
Content-type: text/html

<HTML>
    <BODY>
    This is a test
    </BODY>
</HTML>








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

Date: Sun, 25 Feb 2001 01:25:45 GMT
From: "Misanthrope" <no@spam.net>
Subject: Re: Perl and Frames
Message-Id: <taZl6.1720$ju2.199967@newsread2.prod.itd.earthlink.net>


Go ask someone on an html or browser newsgroup.


"Edward Meyer" <ejmeyer@concentric.net> wrote in message
news:979l0h$rd1@dispatch.concentric.net...
> I am trying to reload multiple frames in 1 CGI script I have tried the
> "Window-target:" HTTP header but can not get it to work.  The following it
> the output of my script.  It does appear to work for netscape but not IE5.
> Is there something I can use for IE5?
>
> Window-target: _top
> Content-type: text/html
>
> <HTML>
>     <BODY>
>     This is a test
>     </BODY>
> </HTML>
>
>
>
>
>
>




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

Date: Sun, 25 Feb 2001 02:19:51 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Perl and Frames
Message-Id: <Pine.LNX.4.30.0102250210210.13967-100000@lxplus003.cern.ch>

On 25 Feb 2001, Edward Meyer wrote:

> I am trying to reload multiple frames in 1 CGI script I have tried the
> "Window-target:" HTTP header but can not get it to work.  The following it
> the output of my script.

Writing grammatical English might or might not help your case; but
nothing that you're asking about has the slightest specificity to Perl
- if you could do it in Perl then you could equally do it in something
else, C++ or COBOL or whatever turns you on.

> It does appear to work for netscape but not IE5.
> Is there something I can use for IE5?

Have you considered designing for the WWW, instead of for some
specific vendor and display situation?  (Have you ever felt a frameset
on a brailler, or heard one on a speaking browser, to say nothing
of the indexing robots?).

HTTP is codified in RFC2616 (which is a standards-track IETF
specification - does that ring any kind of bell?).  Look there and see
what the Window-target: HTTP header does, if anything.

I've little sympathy for frames, so I'd better stop there.

-- 

                "It takes a little more than a sprinkling of pointy
                  brackets to make HTML."  - Nick Kew.




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

Date: Sat, 24 Feb 2001 23:17:19 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl parser
Message-Id: <hrfg9tk57u2m71i13su3jte2i0dkl9gqvv@4ax.com>

jason f krohn wrote:

>Can someone post the code of a parser fro perl.  It's been awhile and i
>acidently deleted mine.  In case im calling it the wrog name it takes the
>formdata out of a url and puts it in an associative array.  Thanks

I think you're referring to "cgi-lib.pl". That one is pretty old, and
not recommended by most people here (but what do they know? ;-). They'd
tell you to use CGI.pm instead (but what do they know? ;-). My advice
would be to use a lighter-weight module, that may even be compatible
with CGI.pm in this regard, such as CGI::Lite, CGI::Minimal,
CGI::Request or CGI::Thin. You can get those through CPAN
(<http://search.cpan.org/>).

-- 
	Bart.


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

Date: 24 Feb 2001 23:59:18 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl Threads -- advice needed
Message-Id: <979hsm$57b$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Dan Sugalski 
<dan@tuatha.sidhe.org>],
who wrote in article <zmQl6.6041$M_1.575493@news1.rdc1.ct.home.com>:
> Creating a new thread per request is a good way to overload your box on
> any OS.

Nope.  OS/2 is *designed* around this paradigm.  Threads are very
cheap (they are reported to be the most-efficient-implementation
around).  Similar things may happen on Hurd too.

> Thread spawning's not free, and if you don't limit the number of
> concurent connections you'll blow through some resource pretty quickly,
> probably either memory or filehandles.

Filehandles *are* sparse resources in the *current implementation* of
Perl on OS/2.  It is possible to increase the filehandles pool of the
process dynamically, but the port does not do it.  I do not think that
the extra memory is of any concern - unless you use the
an-interpreter-per-thread model.

Ilya


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

Date: Sun, 25 Feb 2001 00:45:40 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Perl Threads -- advice needed
Message-Id: <UAYl6.6158$M_1.660286@news1.rdc1.ct.home.com>

Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> [A complimentary Cc of this posting was sent to Dan Sugalski 
> <dan@tuatha.sidhe.org>],
> who wrote in article <zmQl6.6041$M_1.575493@news1.rdc1.ct.home.com>:
>> Creating a new thread per request is a good way to overload your box on
>> any OS.

> Nope.  OS/2 is *designed* around this paradigm.  Threads are very
> cheap (they are reported to be the most-efficient-implementation
> around).  Similar things may happen on Hurd too.

It doesn't matter how cheap they are--spawning new ones is more
expensive than reusing ones in a pool. It's also easier to manage
the number of concurrent connections you're dealing with if you
use a thread pool.

>> Thread spawning's not free, and if you don't limit the number of
>> concurent connections you'll blow through some resource pretty quickly,
>> probably either memory or filehandles.

> Filehandles *are* sparse resources in the *current implementation* of
> Perl on OS/2.  It is possible to increase the filehandles pool of the
> process dynamically, but the port does not do it.  I do not think that
> the extra memory is of any concern - unless you use the
> an-interpreter-per-thread model.

Either way, you're still going to blow out your memory if you're not
careful. There are always resource limitations.

Gnerally speaking, the language and operating system used don't make
much of a difference--good techniques are good, and bad ones aren't.
The language and OS may make you hit the limits sooner, or put them
off a little, but don't make any fundamental difference.

Browsing the archives of comp.programming.threads, or reading
one of the better threading books (I'm fond of both the O'Reilly
book and Butenhof's book) would do anyone good before doing
thread progamming, regardless of the language or operating
system.

				Dan


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

Date: Sat, 24 Feb 2001 22:54:13 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: regex help needed
Message-Id: <3A983CD2.96909AD5@acm.org>

[Please post your replies _after_ the previous quoted text]

[Please remove any quoted text that is not applicable to your reply]


cryofan wrote:
> 
> Thanks for replies. I have basically fixed the problem. One thing I was
> doing wrong was the split; I changed it all-- got much better results. My
> new split obviates the need to smash the characters in front of the "http".
> My new string-end-smasher is  $array1[$num_words] =~ s/>.*$/$blank/;
                                                              ^^^^^^

This is redundant, simply doing $array1[$num_words] =~ s/>.*$//;
accomplishes the same thing.

> One person commented that the problem is that the asterisk above stands for
> zero or more, and that the problem was that it was taking only the zero.
> Well, I don't think that is the case (maybe I misunderstood) b/c it is
> greedy, and takes as many as possible.

Yes, you misunderstood. Although the asterisk (*) is greedy it will stop
at the first match that satifies the requirement for zero or more
characters.
If you want more information on how regular expressions work get the
book "Mastering Regular Expressions" from O'Reilly.

> The above code does do the job--it
> smashes the end of the string---everything inclusive and after the >, till
> the end.
> 
> I still have a one-off problem somewhere, but that will be easy.
> 
> [snip]
> 
> $blank="";
> @array1= split(/href=/,$content);
> $num_words = 0;$num_links=0;

$num_words = $num_links = 0;

> while($num_words <= @array1)

If your '@array1' has five elements then they are numbered 0, 1, 2, 3,
4. At the end of your while loop the variable '$num_words' will be equal
to 5.

> {
>   #if($array1[$num_words]
> =~/href\=http\:\/\/biz\.yahoo\.com\/rb\/[0-9]*\/[a-zA-Z0-9_]*\.html\>\<b\>[a
> -zA-Z0-9_]*/i)
> #href=http://biz.yahoo.com/rb/010222/business_stocks_earnings_dc_2.html><b>T
> ech
>   if($array1[$num_words] =~/^http\:\/\/biz\.yahoo\.com\/rb\/.*/)

Consider using a regex delimiter other than /  This regex is anchored at
the front (^) so the .* at the end is not required in fact it makes the
regex do extra work that it doesn't have to.
    if ( $array1[ $num_words ] =~ m#^http://biz\.yahoo\.com/rb/# )


John


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

Date: Sat, 24 Feb 2001 18:22:06 -0600
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: splice question
Message-Id: <36FEC83E831D28D2.6881EE70E5A1EB7F.6BA0D72862B17289@lp.airnews.net>


"Joseph Pepin" <jdpepin@optonline.net> wrote in message
news:x5Wl6.7692$Vj5.1529479@news02.optonline.net...
: "Rick Delaney" <rick.delaney@home.com> wrote in message
: news:3A982C86.F855A0E8@home.com...
: > [posted & mailed]
: >
: > Joseph Pepin wrote:
: > >
: > > @a = (1, 2, 3, 4, 5, 6);
: > >
: > > @b = splice @a, 0, 4, $a[2], $a[3];
: > >
: > > However, what I get in @b is (1, 2, undef, undef).  @a is left with
(3,
: 4,
: > > 5, 6), what I wanted. Shouldn't @b be (1, 2, 3, 4) ?
: >
: > Yup, and it is in 5.005_03 and up.  What version are you using?
:
: 5.6.0. The same thing happens on both Solaris (built from scratch) and
: ActiveState 623.
:

I ran:
my @a = (1, 2, 3, 4, 5, 6);
my @b = splice @a, 0, 4, $a[2], $a[3];
print Dumper(\@a, \@b);

and got:
$VAR1 = [
          3,
          4,
          5,
          6
        ];
$VAR2 = [
          1,
          2,
          3,
          4
        ];

with ActivePerl 5.6.0.623 on Win98.

HTH,
Charles K. Clarkson






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

Date: Sun, 25 Feb 2001 01:03:01 GMT
From: "Joseph Pepin" <jdpepin@optonline.net>
Subject: Re: splice question
Message-Id: <9RYl6.8234$Vj5.1724696@news02.optonline.net>

Interesting. If I remove the double quotes around the "$_" in the below sub
show, I get the same answer. Now maybe I have another question.

    sub show { my $label = shift; print $label, ': ', join(', ', map(defined
$_ ? "$_" : 'undef', @_)), "\n";}

    my @a = (1, 2, 3, 4, 5, 6, 7, 8);
    my @b = @a;

    show('before', @a);
    show('line a', splice(@a, 0, 4, $a[2], $a[3]));
    show('line b', splice(@b, 0, 4, $b[2] + 0, $b[3] + 0));
    show('after', @a);

before: 1, 2, 3, 4, 5, 6, 7, 8
line a: 1, 2, undef, undef
line b: 1, 2, 3, 4
after: 3, 4, 5, 6, 7, 8

"Charles K. Clarkson" <c_clarkson@hotmail.com> wrote in message
news:36FEC83E831D28D2.6881EE70E5A1EB7F.6BA0D72862B17289@lp.airnews.net...
>
> "Joseph Pepin" <jdpepin@optonline.net> wrote in message
> news:x5Wl6.7692$Vj5.1529479@news02.optonline.net...
> : "Rick Delaney" <rick.delaney@home.com> wrote in message
> : news:3A982C86.F855A0E8@home.com...
> : > [posted & mailed]
> : >
> : > Joseph Pepin wrote:
> : > >
> : > > @a = (1, 2, 3, 4, 5, 6);
> : > >
> : > > @b = splice @a, 0, 4, $a[2], $a[3];
> : > >
> : > > However, what I get in @b is (1, 2, undef, undef).  @a is left with
> (3,
> : 4,
> : > > 5, 6), what I wanted. Shouldn't @b be (1, 2, 3, 4) ?
> : >
> : > Yup, and it is in 5.005_03 and up.  What version are you using?
> :
> : 5.6.0. The same thing happens on both Solaris (built from scratch) and
> : ActiveState 623.
> :
>
> I ran:
> my @a = (1, 2, 3, 4, 5, 6);
> my @b = splice @a, 0, 4, $a[2], $a[3];
> print Dumper(\@a, \@b);
>
> and got:
> $VAR1 = [
>           3,
>           4,
>           5,
>           6
>         ];
> $VAR2 = [
>           1,
>           2,
>           3,
>           4
>         ];
>
> with ActivePerl 5.6.0.623 on Win98.
>
> HTH,
> Charles K. Clarkson
>
>
>
>




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

Date: Sun, 25 Feb 2001 00:34:19 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Substitute on filehandle
Message-Id: <fqYl6.950$C5.43377@eagle.america.net>

On 24 Feb 2001 20:51:35 GMT, Johan Johansson
<johanj@aristotle.algonet.se> wrote:

>Im trying to build a script that opens a textfile as a filehandle and
>goes through all the lines in that textfile and uses the substitute
>command to exchange a word to another one in the file. 
>
>Can someone give me a short example as hint to solve the problem ?
>
>I suppose i should open the filehandle writeable, but shall i open
>another filehandle for the nmput  ?
>
>like 
>
>open(INFILE,"<$my_original_file");
>open(OUTFILE,">>$my_output_file");
>
>and then ? a while loop ? on what shall i use the substitue ?

Your requirement sounds like a classic "filter".  As a matter of fact
Unix already has a program designed to do just what you want -- sed.
The default behavior of sed and most utilities in Unix is to read
their STDIN and write their STDOUT.  

Since these files are already opened in a Perl program and since they
are the default file handles for input and output operations, you
don't really need to mess with explicit opening and closing.  Also,
the substitute operator will default to operating on the $_ variable.
That's real handy, since the input operator can be used in a loop to
place each line of a file in $_ by default: 

  #!/usr/bin/perl -w
  use strict;
  while (<>) {
    s/a_word/another_word/;
    print;
  }

That's the whole thing.  

But why bother with all of that when Perl gives you a command line
switch that will do the 

  while (<>) {
    ...
    print;
  }

part automatically:

  #!/usr/bin/perl -wp
  s/a_word/another_word/;

We can even get it shorter by just typing the program directly on the
command line:

  $ perl -wpe 's/a_word/another_word/;'

Remember, this program will read its STDIN and write its STDOUT, so
you probably want to redirect those file handles right on the command
line like this:  

  $ perl -wpe 's/a_word/another_word/;' < in_file > out_file

Actually, Perl has another command line option that will allow you to
read from STDIN and write to STDOUT and make it look like you updated
the file in place.  It really renames files underneath the covers.
That would be used this way: 

  $ perl -i.bak -wpe 's/a_word/another_word/;' file_name

You can learn about these and other wonderful features in Perl by
reading the manual pages (that are sitting right on your own
computer): 

  perl       Start here to see what's available
  perlop     "I/O operators"
             "Regexp Quote-Like Operators" 
  perlre     Complete discussion of regular expressions
  perlrun    Command line options

-- 
Garry Williams


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

Date: Sat, 24 Feb 2001 14:49:40 -0800
From: "Gary K. Nitzberg" <gknitz@NitzSpace.com>
Subject: time() in GMT Seconds.
Message-Id: <979dob0vcm@enews2.newsguy.com>



Is the time() function, which calculates the number of seconds since the
epoch, based on the number of seconds in your time zone or the number of
seconds in the GMT time zone?


I want to get the number of seconds since the epoch, based on,

        GMT seconds - $x
               where $x is a number in hours.


Thanks.






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

Date: Sun, 25 Feb 2001 00:29:04 GMT
From: Beable van Polasm <beable@my-deja.com>
Subject: Re: time() in GMT Seconds.
Message-Id: <m3vgpzpq60.fsf@beable.van.polasm.bigpond.net.au>

"Gary K. Nitzberg" <gknitz@NitzSpace.com> writes:
> Is the time() function, which calculates the number of seconds since the
> epoch, based on the number of seconds in your time zone or the number of
> seconds in the GMT time zone?

From the manual:
perldoc -f time
       time    Returns the number of non-leap seconds since
               whatever time the system considers to be the epoch
               (that's 00:00:00, January 1, 1904 for MacOS, and
               00:00:00 UTC, January 1, 1970 for most other
               systems).  Suitable for feeding to gmtime() and
               localtime().

So it looks like it's number of seconds from a UTC epoch on "most other
systems". However, on MacOS, it doesn't say what timezone the epoch is
in. Do you know that UTC is approximately equal to GMT?

> I want to get the number of seconds since the epoch, based on,
> 
>         GMT seconds - $x
>                where $x is a number in hours.

Why would you subtract hours from seconds?

cheers
Beable van Polasm
-- 
http://members.nbci.com/_______/index.html    IQC 78189333


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

Date: Sat, 24 Feb 2001 23:56:53 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Variable Cross Reference Listing
Message-Id: <3A984AB0.372CA67E@rochester.rr.com>

Bret Tucker wrote:
> 
> Is there any way to get a cross-reference listing of variables in a Perl
> program?
> 
> Specifically, for all program variables:
> 
> a. those that are declared but unused
> 
> b. those that are declared and where they are used in the program according
> to the line number(s) in the program
> 
> Any help greatly appreciated,
> Bret
perl -MO=Xref foo.pl
-- 
Bob Walton


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

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


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