[17633] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5053 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 7 09:05:31 2000

Date: Thu, 7 Dec 2000 06:05:10 -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: <976197910-v9-i5053@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 7 Dec 2000     Volume: 9 Number: 5053

Today's topics:
        Alternating Prints from Two Files <e.roselli@volusoft.com>
    Re: Alternating Prints from Two Files <cingram-at-pjocs-dot-demon-dot-co-dot-uk>
    Re: Alternating Prints from Two Files (Rafael Garcia-Suarez)
        Apache on Linux - Error on scripts called thru browser <cmon_209@hotmail.com>
    Re: Beginner's question (Abigail)
        Comparing two folders then writing difference to file. <stewart@webslave.dircon.co.uk>
    Re: help getting started with Active perl win32 <tick.toff@spam.com>
        Help with Globbing and File Handling <e.roselli@volusoft.com>
    Re: How can I access seconds since the epoch? (Stan Brown)
    Re: How to insert Perl Code inside E-mail text? (Colin Watson)
    Re: How to insert Perl Code inside E-mail text? (Colin Watson)
    Re: IOT/Abort trap running using setuid wrapper AIX <ronr@my-deja.com>
    Re: IOT/Abort trap running using setuid wrapper AIX (Martien Verbruggen)
        Linked lists <Koen@Verbeke.net>
        Logging output to a file <cingram-at-pjocs-dot-demon-dot-co-dot-uk>
    Re: Logging output to a file (Tad McClellan)
        Making Perl output window on NT scrollable. <cingram-at-pjocs-dot-demon-dot-co-dot-uk>
        Set Permission on Files (Win32::Perms) alaugusto@my-deja.com
    Re: simple one (James McCallum)
    Re: simple question: how to split a string? (Martien Verbruggen)
    Re: Sorting a hash of hashes by values <W.Hielscher@mssys.com>
    Re: Ugh! I hope I can explain this... <mkuin@globalrangers.com>
    Re: Use PERL or Java? Which is faster? <tt@cryogen.com>
    Re: Which Package Net::FTP (Eric Bohlman)
    Re: XML::Parser/XML::Parser::Expat <godoy@conectiva.com>
    Re: XML::Parser/XML::Parser::Expat (Eric Bohlman)
        Yesterdays Date <bkaiser@trans-it.de>
    Re: Yesterdays Date (Martien Verbruggen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 7 Dec 2000 12:48:50 +0100
From: "Elisa Roselli" <e.roselli@volusoft.com>
Subject: Alternating Prints from Two Files
Message-Id: <90ntfd$kvj$1@wanadoo.fr>

Kind Sages of Perl,

I need your help again to find my way out of the soup for a relatively
simple operation.

I have some files which come from the menus of our 4gl interfaces. Here's
what a typical one looks like:

*****

T  G E S T I O N    D E S    A C H A T S
t  Achats

OpsCommandes fournisseur
C  Saisie des commandes fournisseur
P  #SACDF

OpsVisualisation commandes
C  Visualisation des commandes
P  #VICDF

OpsEdition commande
C  Edition de la commande fournisseur
P  #EDECF

*****

In order to translate this, I have used awk to separate it into two files,
one of which, bearing the suffix ".hea", contains the header letters:

*****
T
t

Ops
C
P  #SACDF

Ops
C
P  #VICDF

Ops
C
P  #EDECF

*****
and the other, bearing the suffix ".cut",  contains the text of the menus:

*****
   G E S T I O N    D E S    A C H A T S
   Achats

   Commandes fournisseur
   Saisie des commandes fournisseur


   Visualisation commandes
   Visualisation des commandes


   Edition commande
   Edition de la commande fournisseur

*****

The ".cut" files, containing the menu text, have now all been translated
into English, and I want to put the two files back together again into a
third, identical to the first except with English in the place of French:
*****
T  M A N A G E M E N T  O F  P U R C H A S E S
t  Purchases

OpsSupplier Orders
C  Entry of Supplier Orders
P  #SACDF

OpsViewing of Orders
C  Viewing of Orders
P  #VICDF

OpsPrinting of Orders
C  Printing of Supplier Order
P  #EDECF

****

I've tried various different structures using while and foreach on the
files, like:

while (<HEAFILE>) {
my @txtLine
$txtLine[0] = <HEAFILE>;
$txtLine[1] = <CUTFILE>;
print OUT $txtLine[0].$txtLine[1]."\n";}

or

foreach $i (<HEAFILE>) {
my @txtLine = ($i,<CUTFILE>);
print OUT join '' => @txtLine; }

But none of these tergivisations, too numerous to bore you with, produce the
desired result: for each line of the HEAFILE, print out that line directly
concatenated with the corresponding line of CUTFILE. I get printing of
alternating lines from each and other such anomalies.

I would be grateful if someone could show me the right way.

Many thanks,

Elisa Francesca Roselli





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

Date: Thu, 7 Dec 2000 12:19:44 -0000
From: "Clyde Ingram" <cingram-at-pjocs-dot-demon-dot-co-dot-uk>
Subject: Re: Alternating Prints from Two Files
Message-Id: <976191152.5534.0.nnrp-04.9e98e5bc@news.demon.co.uk>


Elisa Roselli <e.roselli@volusoft.com> wrote in message
news:90ntfd$kvj$1@wanadoo.fr...
> Kind Sages of Perl,
> ...
> while (<HEAFILE>) {
> my @txtLine
> $txtLine[0] = <HEAFILE>;
> $txtLine[1] = <CUTFILE>;
> print OUT $txtLine[0].$txtLine[1]."\n";}
> ...
> for each line of the HEAFILE, print out that line directly
> concatenated with the corresponding line of CUTFILE. I get printing of
> alternating lines from each and other such anomalies.

Try chomping the linefeed off at least the first of the pair of line
fragments.
If you do not chomp the "\n" from the second fragment, then you do not need
to append "\n" in the printf.  Your choice of style.

    $txtLine[0] = <HEAFILE>;
    chomp $txtline[0];
    $txtLine[1] = <CUTFILE>;
    print OUT $txtLine[0].$txtLine[1];

Does that help?

Regards,
Clyde Ingram




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

Date: Thu, 07 Dec 2000 12:21:22 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Alternating Prints from Two Files
Message-Id: <slrn92v07q.drg.rgarciasuarez@rafael.kazibao.net>

Elisa Roselli wrote in comp.lang.perl.misc:
> 
> while (<HEAFILE>) {
> my @txtLine
> $txtLine[0] = <HEAFILE>;

You're reading HEAFILE twice here.

> $txtLine[1] = <CUTFILE>;
> print OUT $txtLine[0].$txtLine[1]."\n";}
> 
> or
> 
> foreach $i (<HEAFILE>) {
> my @txtLine = ($i,<CUTFILE>);
> print OUT join '' => @txtLine; }
> 
> But none of these tergivisations, too numerous to bore you with, produce the
> desired result: for each line of the HEAFILE, print out that line directly
> concatenated with the corresponding line of CUTFILE. I get printing of
> alternating lines from each and other such anomalies.

You forgot to chomp the lines read from the files.

While you're at using Unix command-line tools, have you looked at
paste(1) ?

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Thu, 07 Dec 2000 12:27:25 GMT
From: CM <cmon_209@hotmail.com>
Subject: Apache on Linux - Error on scripts called thru browser
Message-Id: <90nvn7$7gh$1@nnrp1.deja.com>

Hi.

I am running Perl on Apache .My scripts are running OK when called from
the command prompt.

However when I call them thru the browser I get these *two* messages on
the error_log .


[Thu Dec  7 04:42:31 2000] [error] (2)No such file or directory: exec
of /home/httpd/cgi-bin/test.pl failed

[Thu Dec  7 04:42:31 2000] [error] [client 192.168.100.132] Premature
end of script headers: /home/httpd/cgi-bin/test.pl


To clarify

For the first error--> the file *does* exist in the specified directory.
Forthe second error--> The Perl file does start with #!/usr/bin/perl.





I have followed the guidelines in

www.apache.org- 'Running CGI scripts on server' documentation


and made sure that all the .conf files

httpd.conf
srm.conf
access.conf

are as per requirements.



Since I am used to Perl on Windows I am finding it difficult to grasp
the other parameters that are involved in Linux.

I have been sitting on this for 5 hours now with two 10 minute
breaks ....so I guess if somebody can help me out with this I will
really *appreciate* it.

[yawn] Thank  you very much!!










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


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

Date: 7 Dec 2000 11:17:32 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Beginner's question
Message-Id: <slrn92usec.734.abigail@tsathoggua.rlyeh.net>

On Thu, 7 Dec 2000 20:33:32 +1100, Martien Verbruggen (mgjv@tradingpost.com.au) wrote in comp.lang.perl.misc <URL: news:<slrn92umbc.20m.mgjv@martien.heliotrope.home>>:
++ On 7 Dec 2000 09:09:47 GMT,
++ 	Abigail <abigail@foad.org> wrote:
++ > On 5 Dec 2000 20:03:30 -0600, Logan Shaw (logan@cs.utexas.edu) wrote in comp.lang.perl.misc <URL: news:<90k6pi$e3i$1@pip.cs.utexas.edu>>:
++ > ++ 
++ > ++ That, of course, is not possible.  You need a functioning computer to
++ > ++ run Perl scripts.
++ > 
++ > 
++ > Nah, anyone can admire a Perl program and run it in their heads.
++ 
++ Is your head Turing-complete?
++ 


Yes.



Abigail


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

Date: Thu, 07 Dec 2000 11:39:50 GMT
From: Stew Dean <stewart@webslave.dircon.co.uk>
Subject: Comparing two folders then writing difference to file.
Message-Id: <90nsu5$5cg$1@nnrp1.deja.com>

Hi,

My perl is rusty so the more help I can get the better here. I'm
looking for a application or script to compare two folders and then
write these to a new folder. Idealy this should have a web front end to
allow files to be over written.

This is so that files altered localy can be zipped up and sent to the
live server so I'd be very suprised if someone somewhere hasnt created
such a tool.

If you could email if you help I'd be very thankful.

Cheers
--
Stewart Dean
http://www.webslave.dircon.co.uk


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


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

Date: Thu, 07 Dec 2000 11:31:08 GMT
From: "SuperGumby" <tick.toff@spam.com>
Subject: Re: help getting started with Active perl win32
Message-Id: <0yKX5.8025$xW4.64569@news-server.bigpond.net.au>

I started at perldoc perldata and read the lot, think I might go through a
few more tutorials.

tks anyway

Eric Bohlman wrote in message <90noon$d0g$2@bob.news.rcn.net>...
>SuperGumby <tick.toff@spam.com> wrote:
>> <snip>





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

Date: Thu, 7 Dec 2000 12:53:23 +0100
From: "Elisa Roselli" <e.roselli@volusoft.com>
Subject: Help with Globbing and File Handling
Message-Id: <90ntnr$jim$1@wanadoo.fr>

I have several hundred files in a directory, in pairs with identical names
and different suffixes, like "*.hea" and "*.cut". I wish to evoke both files
of the pair with  file-handles that would treat them recursively as input
and output to a file with the same name as the other two, but without the
suffix. What is the exact syntax for globbing and file handling in one go?
Can it be done? I tried this, full of naive hope:

open(HEAFILE, glob "<E:\\menu\\en_menu\\*.hea")|| die "Je ne peux pas
ouvrir: $!";
open(CUTFILE,"glob<E:\\menu\\en_menu\\*.cut")|| die "Je ne peux pas ouvrir:
$!";
open(OUT, glob">E:\\menu\\en_menu\\*")|| die "Je ne peux pas ouvrir: $!";

but obviously that didn't work.

Thanks very much to anyone who patient enough to bear with me.

Elisa Franesca Roselli




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

Date: 7 Dec 2000 06:42:00 -0500
From: stanb@panix.com (Stan Brown)
Subject: Re: How can I access seconds since the epoch?
Message-Id: <90nt28$a1c$1@panix6.panix.com>

In <3a2f0493$1@news.cc.umr.edu> "LimboStar" <dontspamme@awdang.com> writes:

>"Stan Brown" <stanb@panix.com> wrote...
>>
>> Question is, how can I easily obtain this value in perl?

>I just answered this (or mentioned it, anyway) in another thread.

>time() returns the time in seconds since the epoch.


	Ah, thanks you. I had overlooked this, and only found localtime()

	My apologies.



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

Date: 7 Dec 2000 11:38:54 GMT
From: cjw44@flatline.org.uk (Colin Watson)
Subject: Re: How to insert Perl Code inside E-mail text?
Message-Id: <90nsse$3qn$1@riva.ucam.org>

Amine Laghaout <alaghaout@trentu.ca> wrote:
>I have an e-mailing program which works this way:
>------------------------------------------
>     open(MAIL, "|$MAIL_PROG");
>print MAIL <<"(END MAIL)";
>From: someone\@trentu.ca
>To: $instruct_mail
>Subject: Subject
>Reply-To: someone\@trentu.ca
>
>BLABLABLA, here goes the message...
>
>
>(END MAIL)
>	close MAIL;
>------------------------------------------
>
>Here is what I would like to do: write a while loop inside the BLABLA
>message to print out a list stored in a *.csv file. It does not
>work... Is there another way to have some Perl code inside there? 

Well, you have one print statement which prints out some stuff, right?

  print MAIL <<"(END MAIL)";
 ... text which gets written down the pipe to your mail program ...
(END MAIL)

You don't have to just open the pipe, print one here-document down it,
then close the pipe again; you can have as much code as you like between
the open and the close. There's nothing to stop you doing things like
this:

  open MAIL, "|$MAIL_PROG" or die "Couldn't start $MAIL_PROG: $!";
  print MAIL <<EOF;
 ... headers of mail ...

 ... start of mail body ...
EOF
  foreach my $line (@lines) {
    print MAIL $line;           # or whatever
  }
  print MAIL <<EOF;
 ... end of mail body ...
EOF
  close MAIL or die $! ? "Couldn't close pipe to $MAIL_PROG: $!"
                       : "$MAIL_PROG returned exit status $?";

Notice that I'm checking the return codes from open() and close(), which
you need to do if you're writing to a pipe (you should always check what
open() returns in any case). See 'perldoc -f close' for more
information.

-- 
Colin Watson                                     [cjw44@flatline.org.uk]
"DRIVE LETTERS SUCK ROTTING WALRUSES THROUGH A LEAKY OIL PIPELINE!"
 - Peter da Silva, scary.devil.monastery


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

Date: 7 Dec 2000 11:44:16 GMT
From: cjw44@flatline.org.uk (Colin Watson)
Subject: Re: How to insert Perl Code inside E-mail text?
Message-Id: <90nt6g$3v8$1@riva.ucam.org>

WA Support wrote:
>open(INFILE, "+</path/to/.cvs/file");
>
>        open (MAIL, "|/bin/sendmail\"$someone\"\@foobear.com");
>        print MAIL "TO: \"$someone\"\@foobear.com\n";
>        print MAIL "FROM: $someoneelse\@foo.com (*** Whatever ***)\n";
>        print MAIL "SUBJECT: Whatever\n\n";
>        print MAIL "$leadin_message\n";
>        while (<INFILE>) {
>            print MAIL "$_\n";
>         }
>         print MAIL "$leadout_message\n";
>        close(MAIL);
>
>close(INFILE);

Spectacular - unnecessary read-write access, no checking of open/close,
loads of backslashes, extra newlines when you copy from INFILE, clumsy
quoting when here-docs would have been better, unusual path to sendmail
which probably shouldn't exist, no space between sendmail and its
arguments ... I'm impressed. :(

-- 
Colin Watson                                     [cjw44@flatline.org.uk]
"Oh Danny Boy, the pipes, the pipes are calling,
 From glen to glen, and down the mountainside ..."


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

Date: Thu, 07 Dec 2000 12:16:19 GMT
From: Ronald J.H. Rood <ronr@my-deja.com>
Subject: Re: IOT/Abort trap running using setuid wrapper AIX
Message-Id: <90nv2e$721$1@nnrp1.deja.com>

In article <slrn92umoa.20m.mgjv@martien.heliotrope.home>,
  mgjv@tradingpost.com.au wrote:
> On Thu, 07 Dec 2000 08:47:02 GMT,
> 	Ronald J.H. Rood <ronr@my-deja.com> wrote:
> > Hi,
> >
> > I made a little perl script that uses net::Ping to do icmp pings.
For
> > this reason it needs to use root privilege. So I made a little
binary,
> > made it setuid root:system to call my script.
> >
> > All I get is IOT/Abort trap
>
> But Perl isn't giving you any errors, is it? Migth it be your system
> doing this? Might you be doing something wrong somewhere? Hard to
tell.

Thanks for the reaction Martien,

In the mean time I fixed part of the problem. The error went away after
removing the -u flag. The icmp ping now works fine but ...
a new problem came in.


I heard of sudo but I am afraid the problem is hidden in my code. It
will have something to do with subroutines, parameters, scoping.
Debugging_mode=ON.

--
Ronald
http://ronr.nl/unix-dba
The best way to accellerate a computer 'running' windows is by
gravitation


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


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

Date: Thu, 7 Dec 2000 23:46:50 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: IOT/Abort trap running using setuid wrapper AIX
Message-Id: <slrn92v1lq.20m.mgjv@martien.heliotrope.home>

On Thu, 07 Dec 2000 12:16:19 GMT,
	Ronald J.H. Rood <ronr@my-deja.com> wrote:
> In article <slrn92umoa.20m.mgjv@martien.heliotrope.home>,
>   mgjv@tradingpost.com.au wrote:
>> On Thu, 07 Dec 2000 08:47:02 GMT,
>> 	Ronald J.H. Rood <ronr@my-deja.com> wrote:
>> > Hi,
>> >
>> > I made a little perl script that uses net::Ping to do icmp pings. For
>> > this reason it needs to use root privilege. So I made a little binary,
>> > made it setuid root:system to call my script.
>> >
>> > All I get is IOT/Abort trap
>>
>> But Perl isn't giving you any errors, is it? Migth it be your system
>> doing this? Might you be doing something wrong somewhere? Hard to
> tell.
> 
> Thanks for the reaction Martien,
> 
> In the mean time I fixed part of the problem. The error went away after
> removing the -u flag. The icmp ping now works fine but ...
> a new problem came in.

You mean you were running perl with the -u flag and used undump to
create the binary you talked about above? Or were you running perl with
-u all the time? If you do, perl will dump core after compiling the
program, but before running it. That's the point of the flag.

Did I misunderstand what you are saying, or did you misunderstand what
-u does? I'm confused.

dump/undump, IIRC, isn't always reliable anyway. 

> I heard of sudo but I am afraid the problem is hidden in my code. It
> will have something to do with subroutines, parameters, scoping.
> Debugging_mode=ON.

yes, but sudo would allow you to write a program the normal way (I'd
still use the -T flag), and rely on the sudo binary to do the right
setuid things.

Did you have a look at perlsec, as I suggested?

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia                  | 


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

Date: Thu, 07 Dec 2000 11:56:58 GMT
From: Koen Verbeke <Koen@Verbeke.net>
Subject: Linked lists
Message-Id: <Pine.LNX.4.21.0012071358000.2685-100000@anfalas.middle-earth>

Hi

Can someone give me an example of a linked list and tell me the story
behind it?

Thanks!



Bye,
	- Koen



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

Date: Thu, 7 Dec 2000 12:44:49 -0000
From: "Clyde Ingram" <cingram-at-pjocs-dot-demon-dot-co-dot-uk>
Subject: Logging output to a file
Message-Id: <976192969.6170.0.nnrp-04.9e98e5bc@news.demon.co.uk>

Are there any slick ways to copy output on a particular file handle to a log
file?

A crude solution is to output via a function which silently copies
everything it is given to a logfile as well as doing the normal output.

I suspect a solution may involve forking a child process, somehow along the
lines of recipe 16.5 (I think) in the Perl Cookbook.

Thanks for helpful suggestions,
Clyde




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

Date: Thu, 7 Dec 2000 07:57:59 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Logging output to a file
Message-Id: <slrn92v2an.ub4.tadmc@magna.metronet.com>

Clyde Ingram <cingram-at-pjocs-dot-demon-dot-co-dot-uk> wrote:

>Are there any slick ways to copy output on a particular file handle to a log
>file?

Perl FAQ, part 5:

   "How do I print to more than one file at once?"


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


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

Date: Thu, 7 Dec 2000 12:49:50 -0000
From: "Clyde Ingram" <cingram-at-pjocs-dot-demon-dot-co-dot-uk>
Subject: Making Perl output window on NT scrollable.
Message-Id: <976192969.6170.1.nnrp-04.9e98e5bc@news.demon.co.uk>

I have a number of Perl scripts, on NT, which pop-up the usual window to
trace STDOUT and STDERR output.

They spew out shedload of useful trace information.
Sadly, I cannot PageUp to look back at what has just scrolled out of view.

Can anyone say how to add scrollbars and a nice long memory buffer to this
window?

Thank-you,
Clyde




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

Date: Thu, 07 Dec 2000 12:07:34 GMT
From: alaugusto@my-deja.com
Subject: Set Permission on Files (Win32::Perms)
Message-Id: <90nui2$6ki$1@nnrp1.deja.com>

Do I have to be the owner of the object (file,directory) that I am
trying to set ACL permission (NT using Win32::Perms)??

------------------------
I am trying to apply permissions to remote files and folders. I log as
administrator of the domain on the PDC. If I execute the script having
as target files owned by administrator, it works good and it applies my
new permissions.

But If I execute the script having as target, files that the ownership
is other users, the script does not apply or modify any permission.

Why is that?
How can I solve this problem?

Should I take the ownership of all files and then apply the permission?
--------------------------

thanks
Alaugusto


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


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

Date: Thu, 07 Dec 2000 11:18:24 GMT
From: james.mccallum@bradford.gov.uk (James McCallum)
Subject: Re: simple one
Message-Id: <3a2f7170.94706433@newscore.theplanet.net>

Thanks,
all those techniques work well,  I guess
that was basic stuff, can anyone
recommend a good book.
Thanks again


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

Date: Fri, 8 Dec 2000 00:09:48 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: simple question: how to split a string?
Message-Id: <slrn92v30r.20m.mgjv@martien.heliotrope.home>

On Thu, 07 Dec 2000 11:02:21 GMT,
	Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
> jnc@oxys-sprl.com wrote in comp.lang.perl.misc:
> 
>> I have the following string: Generic_106541-11
>> and I want to obtain the digits after the - sign.

I wouldn't bother writing code for that. You only have one string
(stated above), and the answer to your question for that string is 11.
Just hardcode it.

Or do you have more? So... What is the general format of all these
strings?

> How to do it using split:
> 
>   my (undef,$digits) = split /-/, $string;

Hopefully, the other strings that need to be looked at don't contain
more than one hyphen. Not stated that it's possible, but also not
excluded. And even then, we don't know whether the digits after the
first or last hyphen are needed.

Doesn't it suck if a problem is only partly specified?

> Other way to do it:
> 
>   my ($digits) = $string =~ /-(.*)/;

You should be safe to assume that there are only digits (explicitly
stated), and that there is at least one (implicit):

my ($digits) = $string =~ /-(\d+)/;

To the OP:

Some others, with the same, more, or different assumptions. The sample
space is so small, that it may be hard to assume that all strings will
look exactly like the one presented, have the same number of characters,
the same number of hyphens, or the same number of digits after the
(last) hyphen. he following each assume a different thing, and all will
arrive at the same answer for the string provided.

Pick the one from these or the above that really will work with all your
strings.

# All digits between the last hyphen and the end.
# This will not allow any characters other than digits there.
($digits) = $string =~ /-(\d+)$/;

# No need for the hyphen, just get all digits at the end of the string.
($digits) = $string =~ /(\d+)$/;

# Get everything after the last hyphen. Also see above.
$digits = (split /-/, $string)[-1];

# Just get the last two characters. They're always digits, and there are
# always exactly 2. This will be fastest.
$digits = substr $string, -2;

Other, sillier solutions with loops, arrays, reversions, pack/unpack,
splice, map, join, index and rindex are possible, but they all boil down
to the same set of assumptions as the ones above.

Pick one. And please, next time, try to describe your problem a bit more
fully. Ok?

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | What's another word for Thesaurus?
NSW, Australia                  | 


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

Date: Thu, 07 Dec 2000 14:29:41 +0100
From: Wolfgang Hielscher <W.Hielscher@mssys.com>
Subject: Re: Sorting a hash of hashes by values
Message-Id: <3A2F90C5.9E89A003@mssys.com>

Geoff Soper schrieb:
> In article <3A2E8E8A.4E75E3A9@mssys.com>,
>    Wolfgang Hielscher <W.Hielscher@mssys.com> wrote:

Hmmm, I thought I cancelled that one but anyway...


> > > $database{"jim"}{"hair"}="ginger"
> 
> > Some semicolons would've been fine, maybe in exchange for some
> > unnescessary double-quotes?! ;)
> 
> Really? I take it you mean the quotes inside the curly brackets? I have no
> idea where I got that idea from, I am pretty new to Perl (and
> programming!), that's a hell of a lot of unecessary quotes in my code!!

You don't need the quotes inside the braces (curly brackets) because in
a hash values are being looked up using key _strings_. So if you
reference a hash entry, the key you use will be automatically be quoted
if it looks like a bare word. The other way round you sometimes may
supply quotes to emphasize that you really wanted a string. For example
	$database{jim}{shift} = '7pm-3am';
is the same as
	$database{jim}{'shift'} = '7pm-3am';
but NOT the same as
	$database{jim}{ shift() } = '7pm-3am';

And sometimes your really must use quotes:
	$database{jim}{'shoe size'} = 12;


>	 I
> didn't indend it to be usable code but with hindsight that would have been
> helpful.

But you should always try to give the people you're asking for help
usable things, like your real code that doesn't work or the real data
you're having problems with, because every additional minute that might
be nescessary to reconstruct your problem will drive more people off.
So giving six lines of representative data (for your problem) was a
really good idea. I just could resist making a ;)-remark, because I
copied-and-pasted your data and "wasted a valueable second of my life"
:) adding semicolons to run the code I supplied in my (cancelled)
posting.


Cheers
   Wolfgang


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

Date: Thu, 7 Dec 2000 12:28:33 +0100
From: "Mark Kuin" <mkuin@globalrangers.com>
Subject: Re: Ugh! I hope I can explain this...
Message-Id: <90ns94$l2v$1@news1.xs4all.nl>

This should give you the name of the script (including path) which is
running.

 my @test = caller(0);
 my $name = $test[1];

"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:f6ts2tk0tgfme5ugdshscip1njfh2ig5qc@4ax.com...
> cputek1@my-deja.com wrote:
>
> >I'm calling a subroutine in a perl script from other perscripts
> >(using "required"). How do I tell which script called the subroutine
> >from within the subroutine?
>
> caller()?
>
> --
> Bart.




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

Date: Thu, 7 Dec 2000 11:25:06 GMT
From: Tim Tyler <tt@cryogen.com>
Subject: Re: Use PERL or Java? Which is faster?
Message-Id: <G573pu.2Dx@bath.ac.uk>

In lots of ngs, Kenny Pearce <kenny@kennypearce.net> wrote:

: If my choices were Java or Perl, I'd only use Java for an app that has a
: GUI.

Many would do otherwise:

"Servlets or CGI/Perl?" : http://www.idg.net/crd_java_9-117546.html

Servlets have now become pretty popular.
-- 
__________                  http://alife.co.uk/  http://mandala.co.uk/
 |im |yler  tt@cryogen.com  http://hex.org.uk/   http://atoms.org.uk/


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

Date: 7 Dec 2000 11:29:38 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Which Package Net::FTP
Message-Id: <90nsb2$d0g$5@bob.news.rcn.net>

Bjoern Kaiser <bkaiser@trans-it.de> wrote:
> I'm using ActivePerl which packages do i have to install
> to use Net::FTP

libnet



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

Date: 07 Dec 2000 09:54:57 -0200
From: Jorge Godoy <godoy@conectiva.com>
Subject: Re: XML::Parser/XML::Parser::Expat
Message-Id: <kpn1e8igz2.fsf@wintermute.casa>

On Wed, 06 Dec 2000, swaroop@mediaone.net wrote:
> These modules "die" when a parse error is encountered. Is there some
> way to make them just print an informational message and go on? I'm
> processing a lot of XML files at once, and I'd like to continue on
> to the next file if the parsing of one fails.

eval() each file?


See you,
-- 
Godoy. <godoy@conectiva.com>

Departamento de Publicações       Conectiva S.A.
Publishing Department             Conectiva Inc.


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

Date: 7 Dec 2000 13:17:02 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: XML::Parser/XML::Parser::Expat
Message-Id: <90o2ke$4ja$2@bob.news.rcn.net>

Jorge Godoy <godoy@conectiva.com> wrote:
> On Wed, 06 Dec 2000, swaroop@mediaone.net wrote:
>> These modules "die" when a parse error is encountered. Is there some
>> way to make them just print an informational message and go on? I'm
>> processing a lot of XML files at once, and I'd like to continue on
>> to the next file if the parsing of one fails.

> eval() each file?

Nope.  eval{} each file.  Remember that the string form of eval is a
totally different animal from the block form of eval.  The latter is
Perl's try/catch mechanism.



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

Date: Thu, 7 Dec 2000 13:32:59 -0000
From: "Bjoern Kaiser" <bkaiser@trans-it.de>
Subject: Yesterdays Date
Message-Id: <90o01o$ahv$1@desperado.vew-telnet.net>

Hi

(my $day,my $month,my $year) = (localtime(time))[3,4,5];
gives me todays date but what's the most simple way to get yesterdays date
in the same format?

thx




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

Date: Fri, 8 Dec 2000 00:15:08 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Yesterdays Date
Message-Id: <slrn92v3as.20m.mgjv@martien.heliotrope.home>

On Thu, 7 Dec 2000 13:32:59 -0000,
	Bjoern Kaiser <bkaiser@trans-it.de> wrote:
> Hi
> 
> (my $day,my $month,my $year) = (localtime(time))[3,4,5];
> gives me todays date but what's the most simple way to get yesterdays date
> in the same format?

my ($day, $month, $year) = (localtime(time - 86400))[3,4,5];

And no, this doesn't give anyone any problems around DST changes.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | I'm just very selective about what I
Commercial Dynamics Pty. Ltd.   | accept as reality - Calvin
NSW, Australia                  | 


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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

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


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


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