[28036] in Perl-Users-Digest
Perl-Users Digest, Issue: 9400 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 28 14:05:47 2006
Date: Wed, 28 Jun 2006 11:05:07 -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 Wed, 28 Jun 2006 Volume: 10 Number: 9400
Today's topics:
Date formatting <r.ted.byers@rogers.com>
How to ignore 1st line in a file when reading <pradeep.bg@gmail.com>
Re: How to ignore 1st line in a file when reading <no@email.com>
Re: How to ignore 1st line in a file when reading <veatchla@yahoo.com>
Re: How to ignore 1st line in a file when reading <pradeep.bg@gmail.com>
Re: How to ignore 1st line in a file when reading <simon.chao@fmr.com>
Re: How to ignore 1st line in a file when reading <rvtol+news@isolution.nl>
How to pass an array and scalar as arguments to a subro <fgchan@gmail.com>
Re: How to pass an array and scalar as arguments to a s <no@email.com>
Re: How to pass an array and scalar as arguments to a s <tuser3@gmail.com>
perl module include error <a.mani24@yahoo.com>
Re: perl module include error <john@castleamber.com>
Re: perl module include error <mritty@gmail.com>
Re: Problem with Multi- threaded Server <tzz@lifelogs.com>
Re: Problem with Multi- threaded Server <tzz@lifelogs.com>
puting an excel file into a perl data structure <kaz219@gawab.com>
Question about OP <bol@adv.magwien.gv.at>
Re: Scalable method for searching in relatively big fil xhoster@gmail.com
Re: Searching each element of an array with grep <1usa@llenroc.ude.invalid>
Re: Single-liner for one-line substitute? <hawk007@flight.us>
Re: Single-liner for one-line substitute? <hawk007@flight.us>
substr extracting <mislam@spam.uiuc.edu>
Re: substr extracting <tuser3@gmail.com>
Re: What is Expressiveness in a Computer Language <pc@p-cos.net>
Re: What is Expressiveness in a Computer Language <david.nospam.hopwood@blueyonder.co.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Jun 2006 09:26:55 -0700
From: "Ted" <r.ted.byers@rogers.com>
Subject: Date formatting
Message-Id: <1151512015.083433.72500@p79g2000cwp.googlegroups.com>
I am trying to use Date::Manip, and have most of what I need working.
The final peice, though, is eluding me. The following statement works
fine:
$market_date = DateCalc($file_time,ParseDateDelta("- 1 business
days"));
I does precisely what I need, WRT computation. However, I have yet to
figure out how to tell it I want the date part only, and that the time
part can be discarded.
I may have just missed the relevant part of the documentation that
tells me this, but I haven't found, in the Date::Manip documentation,
how to get only the date part of the return value from DateCalc. How
do I do this?
Thanks
Ted
------------------------------
Date: 28 Jun 2006 08:58:43 -0700
From: "Deepu" <pradeep.bg@gmail.com>
Subject: How to ignore 1st line in a file when reading
Message-Id: <1151510323.898436.223110@i40g2000cwc.googlegroups.com>
Hi all,
I would like to know when reading a file which has around 10 - 20 lines
in it. How can it be done to ignore 1st line and start reading from 2nd
till last.
Example:
FILE0 ## the name will not be same in all the other files ##
FILE1
FILE2
FILE3
FILE4
FILE5
Now i need to read from 2nd line. Can somebody please help me on this.
To read the whole file, i just use:
open (FH, "FileName") || die "Can't open";
while (<FH>) {
push (@array, $_);
}
Thanks
Deep
------------------------------
Date: Wed, 28 Jun 2006 17:10:11 +0100
From: Brian Wakem <no@email.com>
Subject: Re: How to ignore 1st line in a file when reading
Message-Id: <4gfnv3F1n70d4U1@individual.net>
Deepu wrote:
> Hi all,
>
> I would like to know when reading a file which has around 10 - 20 lines
> in it. How can it be done to ignore 1st line and start reading from 2nd
> till last.
>
> Example:
>
> FILE0 ## the name will not be same in all the other files ##
> FILE1
> FILE2
> FILE3
> FILE4
> FILE5
>
> Now i need to read from 2nd line. Can somebody please help me on this.
>
> To read the whole file, i just use:
>
> open (FH, "FileName") || die "Can't open";
>
> while (<FH>) {
> push (@array, $_);
> }
>
> Thanks
> Deep
>
If you are reading into an array then your question may as well be about
skipping the first element of an array.
my @array = qw( first second third fourth fifth );
print "$_\n" foreach @array[1..$#array];
second
third
fourth
fifth
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: Wed, 28 Jun 2006 11:18:52 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: How to ignore 1st line in a file when reading
Message-Id: <e7u9sp$dnq$1@nntp.aioe.org>
Deepu wrote:
> Hi all,
>
> I would like to know when reading a file which has around 10 - 20 lines
> in it. How can it be done to ignore 1st line and start reading from 2nd
> till last.
>
> Example:
>
> FILE0 ## the name will not be same in all the other files ##
> FILE1
> FILE2
> FILE3
> FILE4
> FILE5
>
> Now i need to read from 2nd line. Can somebody please help me on this.
>
> To read the whole file, i just use:
>
> open (FH, "FileName") || die "Can't open";
>
> while (<FH>) {
next if ($. == 1); # <------
> push (@array, $_);
> }
>
> Thanks
> Deep
>
use the variable $. as I've shown above.
see perldoc perlvar for more information regarding $.
--
Len
------------------------------
Date: 28 Jun 2006 09:20:36 -0700
From: "Deepu" <pradeep.bg@gmail.com>
Subject: Re: How to ignore 1st line in a file when reading
Message-Id: <1151511636.316081.75500@d56g2000cwd.googlegroups.com>
Sorry for my incorrect statement.
Brian Wakem wrote:
> Deepu wrote:
> > Hi all,
> >
> > I would like to know when reading a file which has around 10 - 20 lines
> > in it. How can it be done to ignore 1st line and start reading from 2nd
> > till last.
> >
> > Example:
> >
> > FILE0 ## the name will not be same in all the other files ##
> > FILE1
> > FILE2
> > FILE3
> > FILE4
> > FILE5
> >
> > Now i need to read from 2nd line. Can somebody please help me on this.
> >
> > To read the whole file, i just use:
> >
> > open (FH, "FileName") || die "Can't open";
> >
> > while (<FH>) {
> > push (@array, $_);
> > }
> >
> > Thanks
> > Deep
> >
>
>
> If you are reading into an array then your question may as well be about
> skipping the first element of an array.
I am not reading into an array.
basically i will take each line and compare with a pattern.
while (<FH>){
if ($_ =~ /^\s*(\S+)\t+pg:\s+(\S+)/) { ## here i need to start from 2nd
line
## Do something ##
}
}
Thanks for helping me out.
>
>
> my @array = qw( first second third fourth fifth );
> print "$_\n" foreach @array[1..$#array];
>
>
> second
> third
> fourth
> fifth
>
>
>
> --
> Brian Wakem
> Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: 28 Jun 2006 09:26:57 -0700
From: "it_says_BALLS_on_your forehead" <simon.chao@fmr.com>
Subject: Re: How to ignore 1st line in a file when reading
Message-Id: <1151512016.942233.284630@j72g2000cwa.googlegroups.com>
Deepu wrote:
> Sorry for my incorrect statement.
>
> Brian Wakem wrote:
> > Deepu wrote:
> > > Hi all,
> > >
> > > I would like to know when reading a file which has around 10 - 20 lines
> > > in it. How can it be done to ignore 1st line and start reading from 2nd
> > > till last.
> > >
> > > Example:
> > >
> > > FILE0 ## the name will not be same in all the other files ##
> > > FILE1
> > > FILE2
> > > FILE3
> > > FILE4
> > > FILE5
> > >
> > > Now i need to read from 2nd line. Can somebody please help me on this.
> > >
> > > To read the whole file, i just use:
> > >
> > > open (FH, "FileName") || die "Can't open";
> > >
> > > while (<FH>) {
> > > push (@array, $_);
> > > }
> > >
> > > Thanks
> > > Deep
I would do the following, so I don't have to perform a check inside the
loop for every iteration:
open my $fh, '<', $file or die "can't open $file: $!\n";
chomp( my $first_line = <$fh> );
while ( <$fh> ) {
# do whatever.
}
close $fh or die "can't close $file: $!\n";
HTH.
------------------------------
Date: Wed, 28 Jun 2006 18:46:58 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: How to ignore 1st line in a file when reading
Message-Id: <e7uirh.17g.1@news.isolution.nl>
Deepu schreef:
> I would like to know when reading a file which has around 10 - 20
> lines in it. How can it be done to ignore 1st line and start reading
> from 2nd till last.
> [...]
> open (FH, "FileName") || die "Can't open";
>
> while (<FH>) {
> push (@array, $_);
> }
You could use:
push @array, $_ if ($. > 1) ;
Variant:
#!/usr/bin/perl
use strict ;
use warnings ;
my $filename = q[FileName] ;
open my $fh, q[<], $filename or die qq[Cannot open $filename: $!] ;
@array = <$fh> ;
shift @array ;
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 28 Jun 2006 09:16:57 -0700
From: "TheOrangeRemix" <fgchan@gmail.com>
Subject: How to pass an array and scalar as arguments to a subroutine/
Message-Id: <1151511417.331423.22120@p79g2000cwp.googlegroups.com>
I'm writing a Perl script to take in an array and a scalar as two
arguments and pass them to a subroutine.
Each element of the array has contents ########### word ########### and
the scalar being passed is the size of the array.
The subroutine is supposed to strip the '#" from the contents of each
element and just report the "word" in one array, and report the size of
the array in a scalar.
Here is the code:
-------------------------------------------------------------------------------
unhash(@Array_A,$a); # array and size
sub round {
my($number) = shift;
return int($number + .5);
}
sub unhash
{
my(@fieldarray) = @_;
my($sizearray) = shift;
print "$sizearray\n";
for ($i = 0; $i < $sizearray; $i++)
{
if ($fieldarray[$i] =~ m/########### (.*?)#/)
{
$fieldarray[$i] = $1;
}
}
print @fieldarray;
}
-------------------------------------------------------------------------------
What ends up happening is that the subroutine returns the new formatted
array and the size in the first array and returns a blank scalar. What
has happened here and how do I fix it? Thanks.
------------------------------
Date: Wed, 28 Jun 2006 17:29:23 +0100
From: Brian Wakem <no@email.com>
Subject: Re: How to pass an array and scalar as arguments to a subroutine/
Message-Id: <4gfp33F1n7r6bU1@individual.net>
TheOrangeRemix wrote:
> I'm writing a Perl script to take in an array and a scalar as two
> arguments and pass them to a subroutine.
> Each element of the array has contents ########### word ########### and
> the scalar being passed is the size of the array.
> The subroutine is supposed to strip the '#" from the contents of each
> element and just report the "word" in one array, and report the size of
> the array in a scalar.
>
> Here is the code:
>
> -------------------------------------------------------------------------------
>
> unhash(@Array_A,$a); # array and size
Switch them around:
unhash($a,@Array_A);
> sub round {
> my($number) = shift;
> return int($number + .5);
> }
>
> sub unhash
> {
> my(@fieldarray) = @_;
> my($sizearray) = shift;
my ($sizearray,@fieldarray) = @_;
BUT:
1) Don't use $a as a variable name.
2) You don't need to know the size of the array, just use a foreach loop
on the array.
3) Even if you did need to know the size of the array, find out when you
need to inside the sub.
4) It is much better to pass a reference to an array than the actual
array as this avoids the problem you have had and uses less memory.
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: 28 Jun 2006 09:49:06 -0700
From: "tuser" <tuser3@gmail.com>
Subject: Re: How to pass an array and scalar as arguments to a subroutine/
Message-Id: <1151513346.347863.326580@x69g2000cwx.googlegroups.com>
TheOrangeRemix wrote:
> sub round {
> my($number) = shift;
> return int($number + .5);
that would be better written as:
return sprintf("%.0f", $number);
> }
see PerlFAQ 4 - "Does Perl have a round() function?"
------------------------------
Date: 28 Jun 2006 09:42:17 -0700
From: "Mani" <a.mani24@yahoo.com>
Subject: perl module include error
Message-Id: <1151512937.397713.118370@y41g2000cwy.googlegroups.com>
Hi,
while trying to run a perl script, in windows machine,
i get the following error,
cant locate /<location>.pm in @INC (@INC contains c:/perl/lib
C:/Perl/site/lib
begin failed --compilation aborted
please let me know to know why compilation aborts and how it can be
solved....
-Mani
------------------------------
Date: 28 Jun 2006 17:23:47 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: perl module include error
Message-Id: <Xns97F07E197CDACcastleamber@130.133.1.4>
"Mani" <a.mani24@yahoo.com> wrote:
> Hi,
>
> while trying to run a perl script, in windows machine,
> i get the following error,
>
> cant locate /<location>.pm in @INC (@INC contains c:/perl/lib
> C:/Perl/site/lib
> begin failed --compilation aborted
>
> please let me know to know why compilation aborts and how it can be
> solved....
What is <location>.pm?
*Always* copy the *exact* message you get.
--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
------------------------------
Date: 28 Jun 2006 10:41:04 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: perl module include error
Message-Id: <1151516464.052477.196250@75g2000cwc.googlegroups.com>
Mani wrote:
> Hi,
>
> while trying to run a perl script, in windows machine,
> i get the following error,
>
> cant locate /<location>.pm in @INC (@INC contains c:/perl/lib
> C:/Perl/site/lib
> begin failed --compilation aborted
>
> please let me know to know why compilation aborts
Because your code (or some code that your code uses) includes the line:
use <location>;
but <location>.pm does not exist in any directory that Perl searches
for modules.
>and how it can be solved....
By either fixing the typo you made in "<location>", or by successfully
downloading and installing the <location> module, or by removing the
"use <location>;" line from your code if it's not necessary.
Paul Lalli
>
> -Mani
------------------------------
Date: Wed, 28 Jun 2006 11:34:47 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Problem with Multi- threaded Server
Message-Id: <g69psgt9tuw.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 28 Jun 2006, janicehwang1325@yahoo.com wrote:
> Here is my testing result today:
>
> - Running on Perl version 5.8.6 on another machine is also having same
> segfault problem. I really don't know why another machine can run while
> the other can't. any idea?
It's a bug, that's all. Bugs are by definition unpredictable in their
behavior and effects, and finding a way to isolate and repeat a bug is
a valuable skill because of their unpredictability. What you've
described is helpful to the IO::Socket::SSL maintainers, but we (on
the comp.lang.perl.misc) are not generally qualified to fix this
problem. Maybe comp.lang.perl.modules would be useful as a venue, but
I would go to the source on this one.
The bottom line is, don't mix threads and SSL until you've talked to
the maintainers of the IO::Socket::SSL module.
Ted
------------------------------
Date: Wed, 28 Jun 2006 11:46:35 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Problem with Multi- threaded Server
Message-Id: <g69lkrh9tb8.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 27 Jun 2006, janicehwang1325@yahoo.com wrote:
> For your information, I am running my program in FreeBSD(should have
> mention earlier, sorry bout this) and connect to the FreeBSD using SSH.
> Therefore, I don't think I can use "stunnel" program for it.
Are you sure `stunnel' is not available on FreeBSD? I find that very
susprising. I don't have a FreeBSD machine available, but as far as I
know FreeBSD is pretty good about general Unix compatibility, and is
one of the major Unix OSs.
You may have to run stunnel as root, IF the port you want to use is
privileged (usually that means it's less than 1024 in a Unix
environment). But otherwise you don't need to be root, so you can run
stunnel as yourself, say on port 5643, and forward to your server that
runs without SSL on port 5642 (the ports can be any unused port number
above 1024). This can be done like this:
stunnel -d 5643 -r 5642 [OPTIONS]
I won't give you any more information here, because it's off-topic for
a Perl newsgroup. You should visit the stunnel home page and read the
documentation if you have more questions, especially about the other
options stunnel takes.
Ted
------------------------------
Date: 28 Jun 2006 09:16:18 -0700
From: "KaZ" <kaz219@gawab.com>
Subject: puting an excel file into a perl data structure
Message-Id: <1151511378.354869.218240@m73g2000cwd.googlegroups.com>
Hello,
I have a script which make a lot of searches into an excel file. I use
Spreadsheet::ParseExcel to read it everytime but it is slow. So I want
to (thanks to Peter J. Holzer) put it into a perl data structure. I
tried this:
------------------
#! /usr/bin/perl
use strict;
use warnings;
use Spreadsheet::ParseExcel;
my $DB_oWkS =
Spreadsheet::ParseExcel::Workbook->Parse('/path/to/ExcelFile')->{Worksheet}[0];
my %bts_db;
for (my $iR = 2 ; (defined $DB_oWkS->{MaxRow}) && ($iR <=
$DB_oWkS->{MaxRow}) ; $iR++) {
my $first = $DB_oWkS->{Cells}[$iR][0]->Value;
my $attr1 = $DB_oWkS->{Cells}[$iR][1]->Value;
my $attr2 = $DB_oWkS->{Cells}[$iR][4]->Value;
my $attr3 = $DB_oWkS->{Cells}[$iR][6]->Value;
my $attr4 = $DB_oWkS->{Cells}[$iR][7]->Value;
$bts_db{$first}{attr1} = $attr1;
$bts_db{$first}{attr2} = $attr2;
$bts_db{$first}{attr3} = $attr3;
$bts_db{$first}{attr4} = $attr4;
}
---------
To search for a "first" value, I do, for example:
if (exists $bts_db{"myValue"}) { return $bts_db{"myValue"}{attr2}; }
else { return 0; }
Now I want to be able to check if a particular attr1 value exists,
whatever the key value is. How do I best do this? Whith a loop? Or is
there any other solution?
BTW, I'd like to know how you call this kind of hash. Is it a hash of
hashes? (Yes I'm a newbie to perl)
------------------------------
Date: Wed, 28 Jun 2006 18:58:47 +0200
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Question about OP
Message-Id: <1151513927.701705@proxy.dienste.wien.at>
Hi folks,
can someone explain the purpose and behaviour of PADOPs,
SVOPs and PVOPs? Why are there OPs (like gvsv) which
are sometime PADOPs and sometime SVOPs?
Maybe this will be still remain an unanswered question, like
the one about cached and cloned CVs, but I ask nevertheless.
Perhaps...
I would also very appreciate if someone could me point to
any link or book relating this theme. It seems this topic is
too deep/down/low to be explained anywhere in the perl
docs. perlguts & friends are just a start (a good start!), but
these details are not mentioned there.
Thanks for your answers, and kind greetings,
Ferry
--
Ing. Ferry Bolhar
Municipality of Vienna, Department 14
A-1010 Vienna / AUSTRIA
E-mail: bol@adv.magwien.gv.at
------------------------------
Date: 28 Jun 2006 16:34:05 GMT
From: xhoster@gmail.com
Subject: Re: Scalable method for searching in relatively big files
Message-Id: <20060628123433.263$be@newsreader.com>
"it_says_BALLS_on_your forehead" <simon.chao@fmr.com> wrote:
> Tad McClellan wrote:
> > KaZ <kaz219@gawab.com> wrote:
> >
>
> >
> > A pattern match should *look like* a pattern match:
> >
> > @line = split /\t/, $line;
>
> I agree with you, Tad. However, From the Programming Perl 3rd ed. book
> pg. 63...
>
> PICK YOUR OWN QUOTES
>
> "You can use whichever nonalphanumeric, nonwhitespace delimiter you
> like in place of '/'."
Can doesn't mean should. And without a compelling reason, you shouldn't.
> An interesting thing about the single quote - it's not supposed to
> interpolate, and if the pattern is a variable, it won't. But in the
> case of at least tab characters '\t', it does.
No, the single quotes send a literal '\t' into the regex. The regex engine
does the interpolation of \t into a tab.
> This behavior is not
> consistent with how tabs behave between single quotes with the print
> function.
That is because print doesn't interpret strings, it prints them. The regex
engine interprets them.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Wed, 28 Jun 2006 16:02:51 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Searching each element of an array with grep
Message-Id: <Xns97F07AA62B9D6asu1cornelledu@127.0.0.1>
Mirco Wahab <peace.is.our.profession@gmx.de> wrote in news:e7tupc$2jg$1
@mlucom4.urz.uni-halle.de:
> Thus spoke Ben Morrow (on 2006-06-27 22:34):
>
>> It is slower, though. A BLOCK has a finite amount of bookkeeping:
>>
>> ~% perl -MBenchmark=cmpthese -e'
>> ...
>> It's always cleaner and often faster to say what you mean.
...
> I didn't expect expression-grep to come out fastest
> at almost all circumstances.
I hadn't either.
> Thanks for this hint!
Me too. (Should I join AOL now?)
Thanks.
Sinan
------------------------------
Date: 28 Jun 2006 08:21:51 -0700
From: "Andrew" <hawk007@flight.us>
Subject: Re: Single-liner for one-line substitute?
Message-Id: <1151508111.076218.95360@d56g2000cwd.googlegroups.com>
Mike Pearson wrote:
> On 28 Jun 2006 09:54:51 GMT, anno4000@zrz.tu-berlin.de wrote:
>
>
> > perl -pi -e '$. == 1 && s/old/new/g' file
>
> Many thanks - that's done the job.
Two variations on the above -- one equivalent, the other for a
different need:
(not sure about the syntax esthetics nor efficiency of these; just
throwing them on the table):
This seems equivalent to the above (modifies ONLY the first line):
perl -pi -e 'next if $done; s/old/new/g; $done++;' file
This one modifies the first match, regardless on which line, and does
nothing beyond that first line:
perl -pi -e 'next if $done; s/old/new/g && $done++;' file
(The latter also lets you re-run the command and alter the subsequent
matching line (provided your particular regex does not match the same
line altered in the previous match) -- a sort of "incremental" way of
doing the standard "perl -pi -e" thing... can't think of a practical
use, but, heck...)
Andrew
------------------------------
Date: 28 Jun 2006 08:37:14 -0700
From: "Andrew" <hawk007@flight.us>
Subject: Re: Single-liner for one-line substitute?
Message-Id: <1151509034.704099.176990@d56g2000cwd.googlegroups.com>
Bad choice of words on my part. Correcting, just to be sure:
> This one modifies the first match, regardless on which line, and does
> nothing beyond that first line:
I should have said, "this one modifies the first line that matches, but
not any subsequent lines that may also match"
perl -pi -e 'next if $done; s/old/new/g && $done++;' file
------------------------------
Date: Wed, 28 Jun 2006 11:41:38 -0500
From: Sharif Islam <mislam@spam.uiuc.edu>
Subject: substr extracting
Message-Id: <e7ubg3$8ir$1@news.ks.uiuc.edu>
I want to extract 'ny' part from the string. 'n' being any number.
#!/usr/bin/perl
use strict;
my $string = "$obj->time('<=','1y')";
if ($string =~ /time/) {
extract($string); }
sub extract {
my $string = shift;
$diff = substr ($string, -4,2);
print $diff; }
Two problems:
1. I get this error when using strict:
Global symbol "$obj" requires explicit package name at a.pl line 3.
The "$obj" is part of the string. So I will need it. Not sure how to
avoid this error.
2. Sometime the string can contain two digit for the year:
$obj->time('<=','11y'). Then the substr will only get part of it. should
I use split? or regex?
------------------------------
Date: 28 Jun 2006 09:58:57 -0700
From: "tuser" <tuser3@gmail.com>
Subject: Re: substr extracting
Message-Id: <1151513937.629943.239930@p79g2000cwp.googlegroups.com>
Sharif Islam wrote:
> I want to extract 'ny' part from the string. 'n' being any number.
>
> #!/usr/bin/perl
> use strict;
I suggest you add "use warnings;".
> my $string = "$obj->time('<=','1y')";
You probably want non-interpolating quotes here (this prevents the
error "Global symbol "$obj" requires explicit package name at a.pl line
3."):
my $string = q{$obj->time('<=','1y')};
> if ($string =~ /time/) {
> extract($string); }
>
> sub extract {
> my $string = shift;
> $diff = substr ($string, -4,2);
> print $diff; }
> 2. Sometime the string can contain two digit for the year:
> $obj->time('<=','11y'). Then the substr will only get part of it. should
> I use split? or regex?
You could use either -- personally I prefer regex, but TIMTOWTDI.
------------------------------
Date: Wed, 28 Jun 2006 18:14:20 +0200
From: Pascal Costanza <pc@p-cos.net>
Subject: Re: What is Expressiveness in a Computer Language
Message-Id: <4gfo6tF1cju7vU1@individual.net>
Matthias Blume wrote:
> Pascal Costanza <pc@p-cos.net> writes:
>
>> Whether you consider something you cannot do with statically typed
>> languages a bad idea or not is irrelevant. You were asking for things
>> that you cannot do with statically typed languages.
>
> The whole point of static type systems is to make sure that there are
> things that one cannot do. So the fact that there are such things are
> not an argument per se against static types.
I am not arguing against static type systems. I am just responding to
the question what the things are that you cannot do in statically typed
languages.
> [ ... ]
>
>> Beyond that, I am convinced that the ability to update a running
>> system without the need to shut it down can be an important asset.
>
> And I am convinced that updating a running system in the style of,
> e.g., Erlang, can be statically typed.
Maybe. The interesting question then is whether you can express the
kinds of dynamic updates that are relevant in practice. Because a static
type system always restricts what kinds of runtime behavior you can
express in your language. I am still skeptical, because changing the
types at runtime is basically changing the assumptions that the static
type checker has used to check the program's types in the first place.
For example, all the approaches that I have seen in statically typed
languages deal with adding to a running program (say, class fields and
methods, etc.), but not with changing to, or removing from it.
>>> Note that prohibiting directly self-modifying code does not prevent a
>>> program from specifying another program to *replace* it.
>> ...and this creates problems with moving data from one version of a
>> program to the next.
>
> How does this "create" such a problem? The problem is there in either
> approach. In fact, I believe that the best chance we have of
> addressing the problem is by adopting the "replace the code" model
> along with a "translate the data where necessary at the time of
> replacement". Translating the data, i.e., re-establishing the
> invariants expected by the updated/replaced code, seems much harder
> (to me) in the case of self-modifying code. Erlang got this one
> right.
...and the "translate the date where necessary" approach is essentially
triggered by a dynamic type test (if value x is of an old version of
type T, update it to reflect the new version of type T [1]). QED.
Pascal
[1] BTW, that's also the approach taken in CLOS.
--
3rd European Lisp Workshop
July 3 - Nantes, France - co-located with ECOOP 2006
http://lisp-ecoop06.bknr.net/
------------------------------
Date: Wed, 28 Jun 2006 16:25:22 GMT
From: David Hopwood <david.nospam.hopwood@blueyonder.co.uk>
Subject: Re: What is Expressiveness in a Computer Language
Message-Id: <S3yog.230709$8W1.24255@fe1.news.blueyonder.co.uk>
Andreas Rossberg wrote:
> David Hopwood wrote:
>
>> (In the case of eval, OTOH,
>> the erroneous code may cause visible side effects before any run-time
>> error occurs.)
>
> Not necessarily. You can replace the primitive eval by compile, which
> delivers a function encapsulating the program, so you can check the type
> of the function before actually running it. Eval itself can easily be
> expressed on top of this as a polymorphic function, which does not run
> the program if it does not have the desired type:
>
> eval ['a] s = typecase compile s of
> f : (()->'a) -> f ()
> _ -> raise TypeError
What I meant was, in the case of eval in an untyped ("dynamically typed")
language.
The approach you've just outlined is an implementation of staged compilation
in a typed language.
--
David Hopwood <david.nospam.hopwood@blueyonder.co.uk>
------------------------------
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 9400
***************************************