[29302] in Perl-Users-Digest
Perl-Users Digest, Issue: 546 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 21 11:09:48 2007
Date: Thu, 21 Jun 2007 08:09: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 Thu, 21 Jun 2007 Volume: 11 Number: 546
Today's topics:
Re: Adding to a perl script automatically <glennj@ncf.ca>
Announce: Spreadsheet::Read-0.23 <h.m.brand@xs4all.nl>
Announce: Text::CSV_XS 0.30 <h.m.brand@xs4all.nl>
Re: date parts in one step <baxter.brad@gmail.com>
Re: date parts in one step <blgl@stacken.kth.se>
Re: date parts in one step <stoupa@practisoft.cz>
Re: package filename mismatches ? <baxter.brad@gmail.com>
Re: Perl Best Practices - Code Formatting. <baxter.brad@gmail.com>
Re: Perl Best Practices - Code Formatting. <stoupa@practisoft.cz>
Re: Reference syntax <baxter.brad@gmail.com>
Re: RegEx Solution Needed <baxter.brad@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Jun 2007 13:54:50 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Adding to a perl script automatically
Message-Id: <slrnf7l0pb.sud.glennj@smeagol.ncf.ca>
At 2007-06-21 06:20AM, "MMWJones@googlemail.com" wrote:
> Hi,
>
> I have a perl cgi script which defines popup_menu and values in the
> drop down list. More values may be added to this over time. People
> that don't know much about the script might not want to enter the
> script and type in values 'manually'.
>
> Is there a way of writing a script that will ask the user for a value
> and be able to access the script and put the value in the correct
> place automatically?
>
> If so how would i go about doing this? In a .pl script or .sh script?
I would store them externally (a text file or DB) so that they can be
updated in any fashion.
However, if you want to keep them in the script, use the __DATA__
filehandle to store them at the end of the file.
#! ...perl
#...
# read the menu items
my @items = sort <DATA>;
chomp @items;
#...
# end of script
exit;
# data starts here
__DATA__
item 1
item 2
foo
bar
etc.
So, new items can just be appended to the script file.
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
------------------------------
Date: Thu, 21 Jun 2007 11:14:44 GMT
From: "H.Merijn Brand" <h.m.brand@xs4all.nl>
Subject: Announce: Spreadsheet::Read-0.23
Message-Id: <JJzpFp.203r@zorch.sf-bay.org>
Spreadsheet::Read-0.23 has entered CPAN as
file: $CPAN/authors/id/H/HM/HMBRAND/Spreadsheet-Read-0.23.tar.gz
size: 64710 bytes
md5: 8d9c6b8f7ca38ef6966724ccc3090b45
No action is required on your part
Request entered by: HMBRAND (H.Merijn Brand)
Request entered on: Thu, 21 Jun 2007 10:51:24 GMT
Request completed: Thu, 21 Jun 2007 10:52:58 GMT
0.23 Thu 21 Jun 2007
- Use IO::Scalar instead of File::Temp when installed
Thanks to David Cantrell for making a OpenBSD test box available!
- use binmode () when opening files
- Also use 3-arg open in test files
- die if test files cannot be opene'ed
0.22 Mon 18 Jun 2007
- 0.21 should already support Text::CSV_PP 1.05
Tested Text::CSV_PP 1.05 on bleadperl.
- Better detection of (not) installed modules
- Module requires perl 5.6.x
0.21 Mon 18 Jun 2007
- Text::CSV_XS uses keep_meta_info instead of get_flags
- Removed always_quote from xlscat's CSV output
0.20 Thu 31 May 2007
- perlcritic OK
- CSV parsing now uses getline (), and auto-detects eol
Assumes first line does not contain embedded eol. This implies that
parsing CSV with embedded eol sequences is now safe.
- As I now also maintain Text::CSV_XS, I changed the references
- Changed TODO's from Text::CSV to Text::CSV_PP (::CSV is dated 1997)
------------------------------
Date: Thu, 21 Jun 2007 11:23:48 GMT
From: "H.Merijn Brand" <h.m.brand@xs4all.nl>
Subject: Announce: Text::CSV_XS 0.30
Message-Id: <JJzpG1.204M@zorch.sf-bay.org>
Text::CSV_XS 0.30 has entered CPAN as
file: $CPAN/authors/id/H/HM/HMBRAND/Text-CSV_XS-0.30.tar.gz
size: 42582 bytes
md5: 33e1562283bcacddd6dadcc5a73e522d
No action is required on your part
Request entered by: HMBRAND (H.Merijn Brand)
Request entered on: Thu, 21 Jun 2007 11:23:07 GMT
Request completed: Thu, 21 Jun 2007 11:23:53 GMT
2007-06-21 0.30 - H.Merijn Brand <h.m.brand@xs4all.nl>
* ,\rx, is definitely an error without binary (used to HANG!)
* Fixed bug in attribute caching for undefined eol
* Cleaned up some code after -W*** warnings
* Added verbatim.
* More test to cover the really dark corners and edge cases
* Even more typo fixes in the docs
* Added error_diag ()
* Added t/80_diag.t - Will not be mirrored by Text::CSV_PP
* Added DIAGNOSTICS section to pod - Will grow
* Small pod niot (abeltje)
* Doc fix in TODO (Miller Hall)
2007-06-08 0.29 - H.Merijn Brand <h.m.brand@xs4all.nl>
* Removed an unused 'use Data::Dumper'
* Added $csv->eof () RT 27424
* Two typo's in the doc's (Amsterdam.pm)
* Modified examples/speed.pl to better show the diffs between=20=
=20
versions
* Cache attribute settings and regain speed of 0.23! and beyond
Relative overall speeds (YMMV, use examples/speed.pl to check),
the 1.0x versions are from Text::CSV_PP.
0.23 0.25 0.26 0.27 0.28 0.29 1.00 1.02 1.05
=3D=3D=3D=3D =3D=3D=3D=3D =3D=3D=3D=3D =3D=3D=3D=
=3D =3D=3D=3D=3D =3D=3D=3D=3D =3D=3D=3D=3D =3D=3D=3D=3D =3D=3D=3D=3D
combine 1 62 61 61 60 58 100 14 14 14
combine 10 41 41 41 42 42 100 6 6 6
combine 100 35 35 36 36 36 100 5 5 5
parse 1 100 92 87 90 81 96 19 19 17
parse 10 95 100 86 97 94 94 15 16 14
parse 100 90 95 84 94 92 100 16 16 14
print io 93 89 91 91 95 100 0 0 6
getline io 90 92 84 87 89 100 0 0 13
---- ---- ---- ---- ---- ---- ---- ---- ----
average 75 75 71 74 73 98 9 9 11
* Removed prototypes
* Added a SPECIFICATION section to the pod
* Safe caching of eol, and a warning in the docs
* Rewrote t/20_file.t do do actual file IO instead of IO_Scalar=20=
=20
fake
* Small optimization for parse (juerd)
* Added make target test_speed
* Merged the items from CAVEAT to SPECIFICATION
* Updated the TODO and Release Plan sections
* Speed up internals by using references instead of copies (juerd)
* Reworked error_input, which also had an undetected internal error
* Added IO tests for lexical IO handles and perlio IO to/from=20=
=20
scalars
------------------------------
Date: Thu, 21 Jun 2007 14:17:41 -0000
From: Brad Baxter <baxter.brad@gmail.com>
Subject: Re: date parts in one step
Message-Id: <1182435461.500063.123150@n2g2000hse.googlegroups.com>
On Jun 21, 8:13 am, "John W. Krahn" <d...@example.com> wrote:
> anno4...@radom.zrz.tu-berlin.de wrote:
> > Paul Lalli <mri...@gmail.com> wrote in comp.lang.perl.misc:
> >> On Jun 20, 12:28 pm, "Petr Vileta" <sto...@practisoft.cz> wrote:
> >>> I need to get month and year values from localtime() so I wrote this:
>
> >>> # get values in Unix format
> >>> my ($month, $year) = (localtime)[4, 5];
> >>> # convert to human format
> >>> $month++;
> >>> $year += 1900;
>
> >>> Is possible to do the same in one step?
>
> > [...]
>
> >> my ($m, $y) = ((localtime)[4] + 1, (localtime)[5] + 1900);
>
> >> ...The second requires two
> >> separate calls to localtime.
>
> > Not necessarily (untested):
>
> > ($m, $y) = ($_->[ 4] + 1, $_->[ 5] + 1900) for [localtime];
>
> > You can't declare $x and $y in the same statement anymore.
>
> Sure you can, just replace the for statement modifier with map:
>
> my ($m, $y) = map { $_->[ 4] + 1, $_->[ 5] + 1900 } [localtime];
>
Another alternative:
my( $m, $y ) = sub { $_[ 4] + 1, $_[ 5] + 1900 }->(localtime);
--
Brad
------------------------------
Date: Thu, 21 Jun 2007 16:33:18 +0200
From: Bo Lindbergh <blgl@stacken.kth.se>
Subject: Re: date parts in one step
Message-Id: <f5e27f$bv4$1@news.su.se>
In article <gXtei.4672$tB5.3810@edtnps90>, "John W. Krahn" <dummy@example.com>
wrote:
> my ($m, $y) = map { $_->[ 4] + 1, $_->[ 5] + 1900 } [localtime];
Or even:
my ($year, $month) = sub { ($_[5]+1900, $_[4]+1) } -> (localtime);
/Bo Lindbergh
------------------------------
Date: Thu, 21 Jun 2007 16:21:43 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: date parts in one step
Message-Id: <f5e1q3$1d7$2@ns.felk.cvut.cz>
Thanks for all. I tested all your solutions but I found that each one with
for() or map() are one line solutions but make 2 or more steps in cycle. My
solution is this:
(localtime)[4,5];
($m, $y) = ($$_[0] + 1, $$_[1] + 1900);
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Thu, 21 Jun 2007 14:01:06 -0000
From: Brad Baxter <baxter.brad@gmail.com>
Subject: Re: package filename mismatches ?
Message-Id: <1182434466.486246.174890@q69g2000hsb.googlegroups.com>
On Jun 20, 1:50 pm, Uri Guttman <u...@stemsystems.com> wrote:
>
> i played with Exporter and it seems that use doesn't even call import if
> passed an empty list (). so use does have a syntactical trick to skip
> importing.
perldoc -f use
If you do not want to call the package's "import"
method (for instance, to stop your namespace from
being altered), explicitly supply the empty list:
use Module ();
That is exactly equivalent to
BEGIN { require Module }
--
Brad
------------------------------
Date: Thu, 21 Jun 2007 14:27:27 -0000
From: Brad Baxter <baxter.brad@gmail.com>
Subject: Re: Perl Best Practices - Code Formatting.
Message-Id: <1182436047.044520.152860@m36g2000hse.googlegroups.com>
On Jun 21, 1:01 am, "Asim Suter" <asu...@cisco.com> wrote:
> I know people feel strongly about code layout/format and "bracing
> technology" - I would like to know
> what folks are using in their scripts and modules.
perldoc perlstyle
And take a look at the source in CPAN to see what authors there do.
--
Brad
------------------------------
Date: Thu, 21 Jun 2007 15:11:11 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Perl Best Practices - Code Formatting.
Message-Id: <f5e1q1$1d7$1@ns.felk.cvut.cz>
Asim Suter wrote:
> K&R style below
> ============
> for my $item ( @list ) {
> .......
> .......
> }
>
> BSD style below
> ============
> for my $item ( @list )
> {
> ....
> ....
> }
>
>
> PS: It does not matter - but I find BSD style more appealing.
I prefer BSD style too because by me this is better readable for human.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Thu, 21 Jun 2007 13:52:23 -0000
From: Brad Baxter <baxter.brad@gmail.com>
Subject: Re: Reference syntax
Message-Id: <1182433943.907095.64410@n2g2000hse.googlegroups.com>
On Jun 20, 6:42 am, tim_milst...@yahoo.co.uk wrote:
> Is this:
>
> my $arg_ref = \@_;
Store a reference to the @_ array in the lexical scalar $arg_ref.
>
> the same as this:
>
> my ($arg_ref) = @_;
Store the value of the first element in the @_ array in the lexical
scalar $arg_ref.
>
> What is the correct way of reading the latter in English, pseudo code?
I suppose the exercise might be clarifying.
--
Brad
------------------------------
Date: Thu, 21 Jun 2007 13:45:54 -0000
From: Brad Baxter <baxter.brad@gmail.com>
Subject: Re: RegEx Solution Needed
Message-Id: <1182433554.863304.55930@m36g2000hse.googlegroups.com>
On Jun 20, 4:59 pm, "Dr.Ruud" <rvtol+n...@isolution.nl> wrote:
> Dr.Ruud schreef:
>
> > Matt White:
> >> So what I have is a line like:
> >> abc123def456ghi789jkl
> >> I want to end up with a list that looks like:
> >> [123,456,789]
>
> > echo abc123def456ghi789jkl |
> > perl -wnle 'print "[", join(",", /\d+/g), "]"'
>
> Variant:
> echo abc123def456ghi789jkl |
> perl -wnle '$"=","; print "[@{[/\d+/g]}]"'
Golf:
echo abc123def456ghi789jkl |
perl -ple'$"=",";$_="[@{[/\d+/g]}]"'
--
Brad
------------------------------
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 V11 Issue 546
**************************************