[29201] in Perl-Users-Digest
Perl-Users Digest, Issue: 445 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 18 14:10:40 2007
Date: Fri, 18 May 2007 11:09:12 -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, 18 May 2007 Volume: 11 Number: 445
Today's topics:
Re: [newbie] Year in two digits; Time with leading zero <nospam@nospam.com>
Re: [newbie] Year in two digits; Time with leading zero <stoupa@practisoft.cz>
Re: [newbie] Year in two digits; Time with leading zero <tony_curtis32@yahoo.com>
Re: Calling alarm more than once <Peter@PSDT.com>
Re: Calling alarm more than once xhoster@gmail.com
CGI.pm filefield return is inconsistent between I.E and <evillen@gmail.com>
Checking the syntax of Perl code <knipknap@gmail.com>
Re: Checking the syntax of Perl code <ts@dionic.net>
Re: Checking the syntax of Perl code <bik.mido@tiscalinet.it>
Re: Checking the syntax of Perl code <uri@stemsystems.com>
Re: Checking the syntax of Perl code <knipknap@gmail.com>
Re: Checking the syntax of Perl code <knipknap@gmail.com>
Inserting text into a HTML file using Perl <Slain.k@gmail.com>
Re: Inserting text into a HTML file using Perl <glex_no-spam@qwest-spam-no.invalid>
List of sample Build::Module Build.PL bumrecordingstudios@gmail.com
Re: Parsing a text file line-by-line: skipping badly-fo denis.papathanasiou@gmail.com
Re: Parsing a text file line-by-line: skipping badly-fo denis.papathanasiou@gmail.com
Re: Parsing a text file line-by-line: skipping badly-fo (Greg Bacon)
Re: Parsing a text file line-by-line: skipping badly-fo denis.papathanasiou@gmail.com
Tracking the RTP Packets Send. soumenrchow@gmail.com
Re: Using "Perl Best Practices" inside-out objects <Peter@PSDT.com>
Re: Using "Perl Best Practices" inside-out objects <Peter@PSDT.com>
Re: Using "Perl Best Practices" inside-out objects <tadmc@augustmail.com>
Re: Using "Perl Best Practices" inside-out objects <bik.mido@tiscalinet.it>
Re: Using "Perl Best Practices" inside-out objects <mritty@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 18 May 2007 12:38:03 +0200
From: Gilles Ganault <nospam@nospam.com>
Subject: Re: [newbie] Year in two digits; Time with leading zero
Message-Id: <ef0r43pdibe9qaopskd93k1b1hoed4gtm0@4ax.com>
On Fri, 18 May 2007 11:18:45 +0200, "Dr.Ruud"
<rvtol+news@isolution.nl> wrote:
>How about "$year % 100"?
[...]
>You forgot the "02" parts:
That did it. Thanks!
------------------------------
Date: Fri, 18 May 2007 16:13:11 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: [newbie] Year in two digits; Time with leading zero
Message-Id: <f2kcc1$1cju$1@ns.felk.cvut.cz>
"Gilles Ganault" <nospam@nospam.com> píse v diskusním príspevku
news:0mnq431eosb3upimj6g4g7jht6tp752ccs@4ax.com...
> Hello
>
> As indicated in the subject line, I don't Perl, but I must
> write a short script in it.
>
> I just need to get the current year in two digits, and time should be
> HH:MM with leading zeros if needed, ie. 10:01 instead of 10:1.
This is simple:
($min, $hrs, $day, $month, $year) = (localtime) [1,2,3,4,5];
$currentdate = sprintf("%02d/%02d/%02d", $day, $month+1,
substr($year,-2,2));
print $currentdate . "\n";
$currenttime = sprintf("%02d:%02d", $hrs,$min);
print $currenttime . "\n";
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Fri, 18 May 2007 10:40:32 -0400
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: [newbie] Year in two digits; Time with leading zero
Message-Id: <f2kdt0$4l4$1@knot.queensu.ca>
Gilles Ganault wrote:
> Hello
>
> As indicated in the subject line, I don't Perl, but I must
> write a short script in it.
>
> I just need to get the current year in two digits, and time should be
> HH:MM with leading zeros if needed, ie. 10:01 instead of 10:1.
I'd go with strftime from POSIX, e.g.
use POSIX qw( strftime );
my $now = strftime( '%y %H:%M', localtime() );
print "$now\n";
Nicely mnemonic solution.
hth
t
------------------------------
Date: Fri, 18 May 2007 12:48:01 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: Calling alarm more than once
Message-Id: <pan.2007.05.18.12.47.59.871623@PSDT.com>
On Fri, 18 May 2007 10:04:23 +0100, Tim Southerwood wrote:
> iulukus@gmail.com wrote:
>
>> Hi,
>> Is it possible to call the alarm more than once. If it is posible,
>> how?
>
> Assuming you are doing this on a typical unix system...
>
> No, unfortunately:
>
> man -S2 alarm
Or on any system that Perl implements alarm():
perldoc -f alarm
[...]
Only one timer may be counting at once. Each call disables the
previous timer, and an argument of 0 may be supplied to cancel
the previous timer without starting a new one. The returned
value is the amount of time remaining on the previous timer.
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
------------------------------
Date: 18 May 2007 16:16:20 GMT
From: xhoster@gmail.com
Subject: Re: Calling alarm more than once
Message-Id: <20070518121622.025$fp@newsreader.com>
iulukus@gmail.com wrote:
> Hi,
> Is it possible to call the alarm more than once.
Yes, but you can't have them nested.
> If it is posible,
> how?
Just do it.
> I couldn't do it in my program:
>
> {
> .....
> .....
> RETRY:print "Send REQUEST to $server\n";
>
> $payload = "x87\x00\x0c\x02\x1b\x62\x1f\x73\x96\x40\x68\x74\xfb\xff
> \xff";
>
> $lpayload = length($payload);
> $dummy = syswrite($remote, $payload, $lpayload); # $remote is my UDP
> socket.
I don't have access to your UDP socket. So I took that part of your
code out, and turned the sysread into a sleep 20. It worked as I expected,
retrying repeatedly.
> print "Send REQUEST \n";
>
> eval {
> local $SIG{'ALRM'} = sub {print "abc";die "alarm\n"};
> alarm 6;
> sysread($remote, $result, 1024); # Read from socket
> alarm 0;
> };
> if ($@) {
> die unless $@ eq "alarm\n"; # propagate unexpected errors
> goto RETRY;
> # timed out
> }
> else {
> print $@;
What is the point of printing $@ when $@ is false?
Perhaps the die-eval is screwing up your socket. If you include an
simplified example for your UDP server, I'd give it a try and see what
happens on my system.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 18 May 2007 10:04:22 -0700
From: "evillen@gmail.com" <evillen@gmail.com>
Subject: CGI.pm filefield return is inconsistent between I.E and Opera/Firefox
Message-Id: <1179507862.702094.92150@o5g2000hsb.googlegroups.com>
Hi
If I have the following line:
my $url = $q->filefield('url','ignored','30');
in my cgi code, a file selector widget is created. I then choose a
file from somewhere on my network. The form is sent to my next cgi
script which displays the value of
$q->param("url")
The problem is that Internet Explorer displays the full relative path
of the file and the filename, e.g.
C:\pcb_data_dump\eco5_01GR_issue3.emp
however the same code run through Opera or Firefox will simply display
the filename with no path e.g.
eco5_01GR_issue3.emp
I really need the full relative path - how can I get hold of it with
Opera or Firefox?
Thanks for any help
Len
------------------------------
Date: 18 May 2007 06:49:50 -0700
From: Samuel <knipknap@gmail.com>
Subject: Checking the syntax of Perl code
Message-Id: <1179496190.890836.218760@q75g2000hsh.googlegroups.com>
Hi,
I have written a code generator (in Perl) that produces Perl code and
would like to throw an assertion if the result contains invalid
syntax. Any idea if there is a way to perform a syntax check that does
not involve firing up a new process with "perl -c" or eval?
-Samuel
------------------------------
Date: Fri, 18 May 2007 15:16:53 +0100
From: Tim Southerwood <ts@dionic.net>
Subject: Re: Checking the syntax of Perl code
Message-Id: <464db555$0$639$5a6aecb4@news.aaisp.net.uk>
Samuel wrote:
> Hi,
>
> I have written a code generator (in Perl) that produces Perl code and
> would like to throw an assertion if the result contains invalid
> syntax. Any idea if there is a way to perform a syntax check that does
> not involve firing up a new process with "perl -c" or eval?
>
> -Samuel
Is there a problem with using eval()?
Tim
------------------------------
Date: Fri, 18 May 2007 16:26:42 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Checking the syntax of Perl code
Message-Id: <0sdr43h9t5bq5f1n6ijm9skpfj4g73fenf@4ax.com>
On 18 May 2007 06:49:50 -0700, Samuel <knipknap@gmail.com> wrote:
>Subject: Checking the syntax of Perl code
perl -c
>I have written a code generator (in Perl) that produces Perl code and
>would like to throw an assertion if the result contains invalid
>syntax. Any idea if there is a way to perform a syntax check that does
>not involve firing up a new process with "perl -c" or eval?
D'Oh! However... no, I don't think so, since "nothing but perl can
parse Perl". However eval() does not fire up a new process, that I
know.
wolfgang:~ [16:24:15]$ perl -e 'eval q{system "ps x"}'
PID TTY STAT TIME COMMAND
18527 ? S 0:01 sshd: blazar@pts/4
18528 pts/4 Ss 0:01 -bash
10213 pts/4 S+ 0:00 perl -e eval q{system "ps x"}
10214 pts/4 R+ 0:00 ps x
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Fri, 18 May 2007 16:11:27 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Checking the syntax of Perl code
Message-Id: <x7abw2ru1d.fsf@mail.sysarch.com>
>>>>> "S" == Samuel <knipknap@gmail.com> writes:
S> I have written a code generator (in Perl) that produces Perl code and
S> would like to throw an assertion if the result contains invalid
S> syntax. Any idea if there is a way to perform a syntax check that does
S> not involve firing up a new process with "perl -c" or eval?
how were you planning on actually compiling this code? if you want it
inside this process you have to use eval STRING. note that any code
outside of subs will be executed. externally you can run perl -c and it
won't execute main level code but use commands will be run and those
modules can execute code. so there really is no way to just test for
perl syntax all by itself.
if you want to see how generated code is evaled and used, check out
Sort::Maker on cpan. it is a very rare problem that needs code
generation and it can be tricky doing it right. why do you think you
need code gen for your problem? i saw one case where someone generated
code for class accessors when closures would have been simpler and
better.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 18 May 2007 10:41:33 -0700
From: Samuel <knipknap@gmail.com>
Subject: Re: Checking the syntax of Perl code
Message-Id: <1179510093.485658.287090@k79g2000hse.googlegroups.com>
On May 18, 4:16 pm, Tim Southerwood <t...@dionic.net> wrote:
> Is there a problem with using eval()?
Well, maybe I made an incorrect assumption there - is there a way to
use eval for checking the syntax *without executing the code* that I
am not aware of?
There is no problem with eval per-se (in fact, I do compile the code
using eval at a later time in the program), but I would like to catch
syntax errors sooner.
-Samuel
------------------------------
Date: 18 May 2007 10:52:12 -0700
From: Samuel <knipknap@gmail.com>
Subject: Re: Checking the syntax of Perl code
Message-Id: <1179510732.832663.251860@e65g2000hsc.googlegroups.com>
On May 18, 6:11 pm, Uri Guttman <u...@stemsystems.com> wrote:
> how were you planning on actually compiling this code? if you want it
> inside this process you have to use eval STRING. note that any code
> outside of subs will be executed.
Ahh, you may be onto something here, I guess wrapping this into a
function should do the trick. I'll try this when I'm back in the
office on Monday.
> why do you think you
> need code gen for your problem?
We are using a highly specialized template language for controlling
appliances, which we compile into Perl code. There are probably other
ways to do this, but none that were similarly easy and straight
forward to do.
Thanks a lot for your help, Guys!
-Samuel
------------------------------
Date: 18 May 2007 06:24:11 -0700
From: Slain <Slain.k@gmail.com>
Subject: Inserting text into a HTML file using Perl
Message-Id: <1179494651.353229.233520@h2g2000hsg.googlegroups.com>
I have a big list of HTML files, which need to be updated with a
common text.
<script language=JavaScript
src="./highlight.js"></script>
I need to add the above line in each of the html files, before the
text "<\head>". All the HTML files have this text and I think some
kind of search on this string and either replacing "</head>" with the
text above and appending "<\head> to it, might be one way to do it or
just find the <\head> part and insert the text before that.
On similar lines, the text below goes towards the end. The problem is
similar to the above one and I think all that needs to be done, is
read the text below from a file, do a similar search for some text
below which this insert part should go and put it there.
<p><script type="text/javascript">var mailSubject = 'Hardware
Overview';
var mailBody = 'Your Technical Support Team hopes this topic will
be helpful: ' + location.href;
var mailDisplay = 'Click here to email this topic.';
document.write(
'<a href="mailto:YourName@YourAddress.com'
+ '?subject=' + escape(mailSubject)
+ '&body=' + escape(mailBody)
+ '">' + mailDisplay + '</a>'
);</script></p>
<script type="text/javascript"
language=JavaScript1.2><!--
beginSearch ();
//--></script>
Any ideas would be helpful. I do not know much about perl and hence
the more the better.
Thanks a lot
------------------------------
Date: Fri, 18 May 2007 10:39:06 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Inserting text into a HTML file using Perl
Message-Id: <464dc89a$0$493$815e3792@news.qwest.net>
Slain wrote:
> I have a big list of HTML files, which need to be updated with a
> common text.
>
>
> <script language=JavaScript
> src="./highlight.js"></script>
>
> I need to add the above line in each of the html files, before the
> text "<\head>". All the HTML files have this text and I think some
> kind of search on this string and either replacing "</head>" with the
> text above and appending "<\head> to it, might be one way to do it or
> just find the <\head> part and insert the text before that.
perl -pi -e 's/search/replace/' *
If you have files in other directories, that './highlight.js' isn't
going to work, use a path relative to the document root.
And, if you have files in other directories...
perl -pi -e 's/search/replace/' `find ./ -name *.html`
Look up what that will/should do, before you run it.
> On similar lines, the text below goes towards the end. The problem is
> similar to the above one and I think all that needs to be done, is
[...]
> <p><script type="text/javascript">var mailSubject = 'Hardware
[...]
> //--></script>
Put that in a separate file, like you did with highlight.js, and use the
same technique as above.
> Any ideas would be helpful. I do not know much about perl and hence
> the more the better.
Then, write it in a language you do know.
BTW: Searching the Internet for 'search replace perl' would
have revealed a lot of helpful code and you'd probably be
finished with this by now.
------------------------------
Date: 18 May 2007 09:51:45 -0700
From: bumrecordingstudios@gmail.com
Subject: List of sample Build::Module Build.PL
Message-Id: <1179507105.795623.173500@k79g2000hse.googlegroups.com>
Hi,
I'm using Module::Build to create a install program for a Perl tool
which has a .pm, .cgi and folder of .tmpl files.
So far I've success with getting the .pm and .cgi files to install,
and I've got the template folder to copy to blib but I've had no
success with getting that template folder (using dat_files) to copy to
the correct path after.
I feel I'm fairly close but missing one minor thing. I didn't write a
specific function, related to the dat files, as the files need no
processing, only to be copied to a live folder.
I'm having a bit of trouble finding examples for this; is there a list
of CPAN modules that makes use of Module::Build so that I could take a
look at the Build.PL in hopes of getting a better grasp on how non-
standard files are installed with the module?
Thanks!
Drew Krakowski
------------------------------
Date: 18 May 2007 06:28:30 -0700
From: denis.papathanasiou@gmail.com
Subject: Re: Parsing a text file line-by-line: skipping badly-formed lines?
Message-Id: <1179494910.871070.242150@h2g2000hsg.googlegroups.com>
> When using "wc qte20070430", is the character count either
> 2147483647 or 4294967295 ?
Neither:
$ wc qte20070430
wc: qte20070430: Input/output error
120760792 518542177 10989232128 qte20070430
> If not, try:
> cat qte20070430 >/dev/null || echo "disk file error"
> sed 's/a/a/' qte20070430 >/dev/null || echo "disk file error"
> dd if=qte20070430 of=/dev/null || echo "disk file error"
> dmesg | tail; tail /var/log/messages
Here they are; except for the dmesg output, there's nothing new to
report:
$ cat qte20070430 >/dev/null || echo "disk file error"
cat: qte20070430: Input/output error
disk file error
$ sed 's/a/a/' qte20070430 >/dev/null || echo "disk file error"
sed: read error on qte20070430: Input/output error
disk file error
$ dd if=qte20070430 of=/dev/null || echo "disk file error"
dd: reading `qte20070430': Input/output error
21463392+0 records in
21463392+0 records out
10989256704 bytes transferred in 400.547484 seconds (27435590 bytes/
sec)
disk file error
$ dmesg | tail; tail /var/log/messages
end_request: I/O error, dev 03:01 (hda), sector 6690920
hda: dma_intr: status=0x59 { DriveReady SeekComplete DataRequest
Error }
hda: dma_intr: error=0x40 { UncorrectableError }, LBAsect=6690987,
high=0, low=6690987, sector=6690832
end_request: I/O error, dev 03:01 (hda), sector 6690832
hda: dma_intr: status=0x59 { DriveReady SeekComplete DataRequest
Error }
hda: dma_intr: error=0x40 { UncorrectableError }, LBAsect=6690987,
high=0, low=6690987, sector=6690840
end_request: I/O error, dev 03:01 (hda), sector 6690840
hda: dma_intr: status=0x59 { DriveReady SeekComplete DataRequest
Error }
hda: dma_intr: error=0x40 { UncorrectableError }, LBAsect=6690987,
high=0, low=6690987, sector=6690920
end_request: I/O error, dev 03:01 (hda), sector 6690920
May 18 08:25:39 localhost kernel: end_request: I/O error, dev 03:01
(hda), sector 6690920
May 18 08:45:50 localhost kernel: hda: dma_intr: status=0x59
{ DriveReady SeekComplete DataRequest Error }
May 18 08:45:52 localhost kernel: hda: dma_intr: error=0x40
{ UncorrectableError }, LBAsect=6690987, high=0, low=6690987,
sector=6690832
May 18 08:45:52 localhost kernel: end_request: I/O error, dev 03:01
(hda), sector 6690832
May 18 08:45:52 localhost kernel: hda: dma_intr: status=0x59
{ DriveReady SeekComplete DataRequest Error }
May 18 08:45:52 localhost kernel: hda: dma_intr: error=0x40
{ UncorrectableError }, LBAsect=6690987, high=0, low=6690987,
sector=6690840
May 18 08:45:52 localhost kernel: end_request: I/O error, dev 03:01
(hda), sector 6690840
May 18 08:52:31 localhost kernel: hda: dma_intr: status=0x59
{ DriveReady SeekComplete DataRequest Error }
May 18 08:52:33 localhost kernel: hda: dma_intr: error=0x40
{ UncorrectableError }, LBAsect=6690987, high=0, low=6690987,
sector=6690920
May 18 08:52:33 localhost kernel: end_request: I/O error, dev 03:01
(hda), sector 6690920
I'm not sure if this means the error is related to the file or to the
(physical) disk itself.
But either way, it's a problem when trying to do a read at that point
in perl.
------------------------------
Date: 18 May 2007 06:31:37 -0700
From: denis.papathanasiou@gmail.com
Subject: Re: Parsing a text file line-by-line: skipping badly-formed lines?
Message-Id: <1179495097.659059.249500@h2g2000hsg.googlegroups.com>
> What does eof($in) return after the while() stops?
>
> If you attempt to read one more line from <$in>, does it
> return undef, or a line from the file, or does it switch
> to reading from STDIN?
It's undef; basically, in perl, the moment it reaches the file
corruption point (regardless of whether I'm using read or <> for line
at a time), the file handle is gone.
So unlike CL (which lets me trap the exception while keeping the file
handle open so I can skip past it), there doesn't seem to be a way to
get beyond the point of the corruption.
------------------------------
Date: Fri, 18 May 2007 14:35:30 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Parsing a text file line-by-line: skipping badly-formed lines?
Message-Id: <134redi42c1e132@corp.supernews.com>
In article <1179495097.659059.249500@h2g2000hsg.googlegroups.com>,
<denis.papathanasiou@gmail.com> wrote:
: So unlike CL (which lets me trap the exception while keeping the file
: handle open so I can skip past it), there doesn't seem to be a way to
: get beyond the point of the corruption.
Did you run my code that used seek calls?
Greg
--
"Tell me more... " I said, honestly. I wanted her to go on
talking. She was talking nonsense, but a man never tires of
nonsense from a beautiful woman.
-- Bill Bonner
------------------------------
Date: 18 May 2007 08:16:11 -0700
From: denis.papathanasiou@gmail.com
Subject: Re: Parsing a text file line-by-line: skipping badly-formed lines?
Message-Id: <1179501371.560200.158970@h2g2000hsg.googlegroups.com>
> Did you run my code that used seek calls?
Yes; just like using <>, the moment the seek got to the corrupted
part, the file handle was lost.
And I couldn't seek past that point: because the file handle would
close, I got the idea of storing the offset, reopening the file
handle, seeking past the offset, but it wouldn't let me.
I suspect it's because I don't know the size of the corrupted area, so
just seeking to offset+n, unless n is large enough that it puts me in
a clear patch, would just get me an undefined file handle again.
It also occurred to me that I could increment offset by 1, and keep
reopening the file handle until I was clear of the corruption, but it
didn't seem like a good way of doing it.
------------------------------
Date: 18 May 2007 04:36:06 -0700
From: soumenrchow@gmail.com
Subject: Tracking the RTP Packets Send.
Message-Id: <1179488166.848966.87970@n59g2000hsh.googlegroups.com>
Hi
I am sending RTP Packets using VLC Player from my machine to
another machine. I have to track the packets send and received. I have
installed Ethereal for tracking the send and received packets. The
Ethereal is working fine. Now I have written a program in Perl that is
showing the information of the received packets. But I cannot track
the RTP Packets send. Can u please suggest me any way of tracking the
RTP Packets send using Perl.
Soumen.
------------------------------
Date: Fri, 18 May 2007 12:30:54 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: Using "Perl Best Practices" inside-out objects
Message-Id: <pan.2007.05.18.12.30.52.799577@PSDT.com>
On Wed, 16 May 2007 04:35:29 -0700, Paul Lalli wrote:
> On May 16, 5:45 am, Peter Scott <P...@PSDT.com> wrote:
>> use Class::Std;
>>
>> my %thing :ATTR( :name<thing> :default<[]> );
>
> I'm 99% sure that doesn't work, as I tried it (albeit with standard
> Perl 5 syntax) only last week. The default attribute can only take
> strings. Array refs don't work. You need to provide a BUILD
> subroutine in which you assign name to [].
Well it works for me :-)
% cat foo
#!/usr/local/bin/perl
use strict;
use warnings;
package Foo;
use Class::Std;
my %thing :ATTR( :name<thing> :default<[3..5]> );
sub things {
my $self = shift;
@{ $self->get_thing };
}
package main;
my $foo = Foo->new;
print "$_\n" for $foo->things;
__END__
% ./foo
3
4
5
% perl -MClass::Std -le 'print VERSION Class::Std'
0.000008
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
------------------------------
Date: Fri, 18 May 2007 12:40:31 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: Using "Perl Best Practices" inside-out objects
Message-Id: <pan.2007.05.18.12.40.29.597656@PSDT.com>
On Wed, 16 May 2007 12:53:20 +0200, Michele Dondi wrote:
> On Wed, 16 May 2007 09:45:59 GMT, Peter Scott <Peter@PSDT.com> wrote:
>
>>my %thing :ATTR( :name<thing> :default<[]> );
>
> I briefly heard about attributes, and I know I could read the docs,
> but I hadn't seen that syntax yet: that is, angular parens. When were
> they introduced? Where are they documented? (I know about their use in
> Perl 6, but that's a whole another story.)
perldoc Class::Std. They're completely peculiar to that module, because
it's parsing the argument of :ATTR itself. Parens and guillemots work
also, and fat comma syntax. Look in the source at the subroutine
_extractor_for_pair_named().
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
------------------------------
Date: Fri, 18 May 2007 07:57:12 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Using "Perl Best Practices" inside-out objects
Message-Id: <slrnf4r8l8.mhg.tadmc@tadmc30.august.net>
Paul Lalli <mritty@gmail.com> wrote:
> You can return an array from a subroutine just fine.
No you can't.
> sub foo {
> my $ref = [ 1, 2, 3, 4, 5 ];
> return @{$ref};
> }
>
> my @stuff = foo();
You can return the _contents_ of an array (a list) from a
subroutine just fine.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 18 May 2007 15:27:04 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Using "Perl Best Practices" inside-out objects
Message-Id: <hbar439fskthj74jpnq45gahvlut9av1pv@4ax.com>
On Fri, 18 May 2007 12:40:31 GMT, Peter Scott <Peter@PSDT.com> wrote:
>>>my %thing :ATTR( :name<thing> :default<[]> );
>>
>> I briefly heard about attributes, and I know I could read the docs,
>> but I hadn't seen that syntax yet: that is, angular parens. When were
>> they introduced? Where are they documented? (I know about their use in
>> Perl 6, but that's a whole another story.)
>
>perldoc Class::Std. They're completely peculiar to that module, because
>it's parsing the argument of :ATTR itself. Parens and guillemots work
>also, and fat comma syntax. Look in the source at the subroutine
>_extractor_for_pair_named().
I kinda understand: but then what's in the "argument" to an attribute
is considered a plain string, that can be parsed at one's will?
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 18 May 2007 07:35:43 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Using "Perl Best Practices" inside-out objects
Message-Id: <1179498943.153182.28330@y80g2000hsf.googlegroups.com>
On May 18, 8:30 am, Peter Scott <P...@PSDT.com> wrote:
> On Wed, 16 May 2007 04:35:29 -0700, Paul Lalli wrote:
> > On May 16, 5:45 am, Peter Scott <P...@PSDT.com> wrote:
> >> use Class::Std;
>
> >> my %thing :ATTR( :name<thing> :default<[]> );
>
> > I'm 99% sure that doesn't work, as I tried it (albeit with standard
> > Perl 5 syntax) only last week. The default attribute can only take
> > strings. Array refs don't work. You need to provide a BUILD
> > subroutine in which you assign name to [].
>
> Well it works for me :-)
>
> % cat foo
> #!/usr/local/bin/perl
> use strict;
> use warnings;
>
> package Foo;
> use Class::Std;
>
> my %thing :ATTR( :name<thing> :default<[3..5]> );
>
> sub things {
> my $self = shift;
> @{ $self->get_thing };
>
> }
>
> package main;
>
> my $foo = Foo->new;
> print "$_\n" for $foo->things;
> __END__
>
> % ./foo
> 3
> 4
> 5
>
> % perl -MClass::Std -le 'print VERSION Class::Std'
> 0.000008
Apparently it's only the Perl5 syntax that doesn't allow it. Changing
your line above to:
my %thing :ATTR( name => 'thing', default => [3..5] );
results in:
Missing initializer label for Foo: 'thing'.
Fatal error in constructor call at ./foo.pl line 18
$ perl -MClass::Std -le 'print VERSION Class::Std'
0.000008
Paul Lalli
------------------------------
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 445
**************************************