[26349] in Perl-Users-Digest
Perl-Users Digest, Issue: 8524 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 14 21:05:27 2005
Date: Fri, 14 Oct 2005 18:05:04 -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 Fri, 14 Oct 2005 Volume: 10 Number: 8524
Today's topics:
Re: Hash of array access tricks. Sorry, long. <lawrence@hummer.not-here.net>
How to get part of a path <John.Smith@mailinator.com>
Re: How to get part of a path <no@email.com>
Re: How to get part of a path <1usa@llenroc.ude.invalid>
Re: How to get part of a path <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 14 Oct 2005 11:11:18 -0700
From: Lawrence Statton N1GAK/XE2 <lawrence@hummer.not-here.net>
Subject: Re: Hash of array access tricks. Sorry, long.
Message-Id: <x7wtkgrmt5.fsf@hummer.i-did-not-set--mail-host-address--so-shoot-me>
"s. keeling" <keeling@spots.ab.ca> writes:
> s. keeling <keeling@spots.ab.ca>:
> > I've built a HoA as so:
> >
> > my %prompt = (
> > FIRST_NAME => [ qq(NULL), qq(NULL), qq(\tFirst name -> ),
> > qq(You MUST supply a first name.\n) ],
> > LAST_NAME => [ qq(NULL), qq(NULL), qq(\tLast name -> ),
> > qq(You MUST supply a last name.\n) ],
> >
> > and so on. I'd like to write to and access $prompt->{$key}[2] when
> > prompting a user for the name, and I'd like to stuff the reply in
> > $prompt{$key}[1], then compare that with $prompt->{$key}[0], which
> > I'll try to supply via a call to mysql. :-)
>
> I should also say for some reason it won't work if I don't declare
> both $prompt and %prompt, ... or should I just be "my"ing the former
> and not the latter? I'll try that too.
>
perhaps this will help you understand...
#!/usr/bin/perl
use strict;
use warnings;
my %prompt = ( FIRST_NAME => [ qw / first name stuff / ] ,
LAST_NAME => [ qw / last name stuff / ] );
my $prompt = { FIRST_NAME => [ qw / different things / ],
LAST_NAME => [ qw / other different things / ] } ;
print "@{$prompt{FIRST_NAME}}\n";
print "@{$prompt->{FIRST_NAME}}\n";
%prompt at $prompt are different variables.... Just WISHING $prompt
to become a refrence to %prompt will not make it so.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer software consists of only two components: ones and
zeros, in roughly equal proportions. All that is required is to
sort them into the correct order.
------------------------------
Date: Fri, 14 Oct 2005 16:41:12 -0400
From: John Smith <John.Smith@mailinator.com>
Subject: How to get part of a path
Message-Id: <IJU3f.11634$HQ3.308617@wagner.videotron.net>
Hi,
I'm trying to get the good_part from those directory path.
The beginning is always the same it is "dev/dir1/"
First case : dev/dir1/good_part -> should return good_part
Second case: dev/dir1/good_part/src ->should return good_part
3 case : dev/dir1/good_aprt/obj/html -> should return good_part
I'm able to get each case one at a time but not all of them
dev\/dir1\/(.*) on dev/dir1/good_part => $1 return good_part
dev\/dir1\/(.*)(\/.*) on dev/dir1/good_part/src => $1 return good_part
but don't work on dev/dir1/good_part
Remi
papaDoc@videotron.ca
------------------------------
Date: Fri, 14 Oct 2005 22:08:02 +0100
From: Brian Wakem <no@email.com>
Subject: Re: How to get part of a path
Message-Id: <3ral1iFip08aU1@individual.net>
John Smith wrote:
> Hi,
>
> I'm trying to get the good_part from those directory path.
> The beginning is always the same it is "dev/dir1/"
>
> First case : dev/dir1/good_part -> should return good_part
> Second case: dev/dir1/good_part/src ->should return good_part
> 3 case : dev/dir1/good_aprt/obj/html -> should return good_part
>
>
> I'm able to get each case one at a time but not all of them
>
> dev\/dir1\/(.*) on dev/dir1/good_part => $1 return good_part
>
> dev\/dir1\/(.*)(\/.*) on dev/dir1/good_part/src => $1 return good_part
> but don't work on dev/dir1/good_part
Just capture as many characters that aren't a / as possible.
dev/dir1/([^/]+)
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: Fri, 14 Oct 2005 21:09:41 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to get part of a path
Message-Id: <Xns96EFAE94B83D7asu1cornelledu@127.0.0.1>
John Smith <John.Smith@mailinator.com> wrote in news:IJU3f.11634
$HQ3.308617@wagner.videotron.net:
> Hi,
>
> I'm trying to get the good_part from those directory path.
> The beginning is always the same it is "dev/dir1/"
>
> First case : dev/dir1/good_part -> should return good_part
> Second case: dev/dir1/good_part/src ->should return good_part
> 3 case : dev/dir1/good_aprt/obj/html -> should return good_part
Please see the posting guidelines to find out how you can make it easier
for people to help you. You made copying and pasting much harder than
necessary.
> I'm able to get each case one at a time but not all of them
>
> dev\/dir1\/(.*) on dev/dir1/good_part => $1 return good_part
>
> dev\/dir1\/(.*)(\/.*) on dev/dir1/good_part/src => $1 return good_part
> but don't work on dev/dir1/good_part
Show code rather than something that resembles code, but isn't.
This particular problem is easy to solve. For portability, I would use
splitdir and catdir from File::Spec:
#!/usr/bin/perl
use strict;
use warnings;
use File::Spec::Functions qw'catdir splitdir';
my @paths = qw(
dev/dir1/good_part
dev/dir1/good_part/src
dev/dir1/good_aprt/obj/html
);
for my $path (@paths) {
my $good = catdir( (splitdir $path)[2, -1] );
print "$good\n";
}
__END__
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Fri, 14 Oct 2005 17:27:35 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to get part of a path
Message-Id: <slrndl0c6n.fst.tadmc@magna.augustmail.com>
John Smith <John.Smith@mailinator.com> wrote:
> 3 case : dev/dir1/good_aprt/obj/html -> should return good_part
^^
^^
Why should it transpose characters for this one?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 8524
***************************************