[30897] in Perl-Users-Digest
Perl-Users Digest, Issue: 2142 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 20 16:09:52 2009
Date: Tue, 20 Jan 2009 13:09:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 20 Jan 2009 Volume: 11 Number: 2142
Today's topics:
Re: Big5?B?VG9tIFl1IMRGpGwsILlxuNzAwKb8NjYzMDg4OFg (Tim McDaniel)
Re: Concatenating regular exprs in a 'grep' call <cwilbur@chromatico.net>
Re: function calls in double quoted strings <michaelgang@gmail.com>
Re: function calls in double quoted strings <RedGrittyBrick@spamweary.invalid>
Re: function calls in double quoted strings <michaelgang@gmail.com>
Re: function calls in double quoted strings <RedGrittyBrick@spamweary.invalid>
Re: function calls in double quoted strings <tadmc@seesig.invalid>
Re: function calls in double quoted strings <tzz@lifelogs.com>
Re: function calls in double quoted strings <tadmc@seesig.invalid>
Re: inputting the ephemerides <tim@burlyhost.com>
Re: inputting the ephemerides <jimsgibson@gmail.com>
Re: Match CASE/END SQL Construct sln@netherlands.com
Re: unable to open file <"kteague at pobox dot com">
Re: unable to open file <tadmc@seesig.invalid>
Re: unable to open file <"kteague at pobox dot com">
Re: unable to open file <tadmc@seesig.invalid>
use hash to name params, then stringify values in speci <DJStunks@gmail.com>
Re: What do you need to have to be considered a Master (Randal L. Schwartz)
Re: What do you need to have to be considered a Master <tadmc@seesig.invalid>
Re: What do you need to have to be considered a Master <tadmc@seesig.invalid>
Re: What do you need to have to be considered a Master <tim@burlyhost.com>
Re: What do you need to have to be considered a Master <cartercc@gmail.com>
Re: What do you need to have to be considered a Master sln@netherlands.com
Re: What do you need to have to be considered a Master <cwilbur@chromatico.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 20 Jan 2009 18:27:51 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Big5?B?VG9tIFl1IMRGpGwsILlxuNzAwKb8NjYzMDg4OFg
Message-Id: <gl5537$jjk$1@reader1.panix.com>
In article <362fa443-3338-48d7-849c-47c4fb6de1e5@z27g2000prd.googlegroups.com>,
<tom_yu_linux_pilot@hotmail.com> wrote:
> T o m Y u F l , q 6 6 3 0 8 8 8 X
> ~ j 6 0
> O l i n u x p i l o t n
> ~ G
> 6 6 T
>
> M F H P \ X @ , \ / P A , N | , A \ ,
> \ N A A P x A , U I T P ~ H K , p O
>
> r e m a r k , \ d F p H , } : w w w . l i n u x u n i o n . n e X
Is *that* what Perl 6 looks like?
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Tue, 20 Jan 2009 15:34:17 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Concatenating regular exprs in a 'grep' call
Message-Id: <86fxjd1zue.fsf@mithril.chromatico.net>
>>>>> "TJM" == Tad J McClellan <tadmc@seesig.invalid> writes:
TJM> Understand the difference between what is "code" and what is
TJM> "data".
>> I'm tempted to ask you to elaborate on this one.
TJM> This can be hard to answer in a 3-minute post to Usenet...
Indeed, at least while we're all using Von Neumann machines.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Tue, 20 Jan 2009 08:09:27 -0800 (PST)
From: david <michaelgang@gmail.com>
Subject: Re: function calls in double quoted strings
Message-Id: <418e7c39-90fb-4718-9ebe-49edc066f5d1@d36g2000prf.googlegroups.com>
On Jan 20, 6:01=A0pm, Josef Moellers <josef.moell...@fujitsu-
siemens.com> wrote:
> david wrote:
> > HI all,
>
> > This is more a question out of curiosity. Is it possible to call a
> > function from a double quoted string. For example
> > print "The absolute value of -2 is abs(-2). This value is bigger than
> > 0"
>
> Have you tried it? What happened? The earth collapsed? Bush got another
> term in office?
>
> --
> These are my personal views and not those of Fujitsu Siemens Computers!
> Josef M=F6llers (Pinguinpfleger bei FSC)
> =A0 =A0 =A0 =A0 If failure had no penalty success would not be a prize (T=
. =A0Pratchett)
> Company Details:http://www.fujitsu-siemens.com/imprint.html
something much more dramatic:
This is the print text:
The absolute value of -2 is abs(-2). This value is bigger than 0
------------------------------
Date: Tue, 20 Jan 2009 16:23:47 +0000
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: function calls in double quoted strings
Message-Id: <4975fa94$0$30306$da0feed9@news.zen.co.uk>
david wrote:
> On Jan 20, 6:01 pm, Josef Moellers <josef.moell...@fujitsu-
> siemens.com> wrote:
>> david wrote:
>>> HI all,
>>> This is more a question out of curiosity. Is it possible to call a
>>> function from a double quoted string. For example
>>> print "The absolute value of -2 is abs(-2). This value is bigger than
>>> 0"
>> Have you tried it? What happened? The earth collapsed? Bush got another
>> term in office?
>>
>> --
>> These are my personal views and not those of Fujitsu Siemens Computers!
>> Josef Mllers (Pinguinpfleger bei FSC)
>> If failure had no penalty success would not be a prize (T. Pratchett)
>> Company Details:http://www.fujitsu-siemens.com/imprint.html
>
> something much more dramatic:
> This is the print text:
> The absolute value of -2 is abs(-2). This value is bigger than 0
Most people think it a mistake to confuse data and code.
If you were determined, you could do so. You might parse the string and
use eval on bits that look like functions. I'd reconsider.
--
RGB
------------------------------
Date: Tue, 20 Jan 2009 08:42:19 -0800 (PST)
From: david <michaelgang@gmail.com>
Subject: Re: function calls in double quoted strings
Message-Id: <dc2455f7-aca3-479e-af58-580b099e3f32@i24g2000prf.googlegroups.com>
On Jan 20, 6:23=A0pm, RedGrittyBrick <RedGrittyBr...@spamweary.invalid>
wrote:
> david wrote:
> > On Jan 20, 6:01 pm, Josef Moellers <josef.moell...@fujitsu-
> > siemens.com> wrote:
> >> david wrote:
> >>> HI all,
> >>> This is more a question out of curiosity. Is it possible to call a
> >>> function from a double quoted string. For example
> >>> print "The absolute value of -2 is abs(-2). This value is bigger than
> >>> 0"
> >> Have you tried it? What happened? The earth collapsed? Bush got anothe=
r
> >> term in office?
>
> >> --
> >> These are my personal views and not those of Fujitsu Siemens Computers=
!
> >> Josef M=F6llers (Pinguinpfleger bei FSC)
> >> =A0 =A0 =A0 =A0 If failure had no penalty success would not be a prize=
(T. =A0Pratchett)
> >> Company Details:http://www.fujitsu-siemens.com/imprint.html
>
> > something much more dramatic:
> > This is the print text:
> > The absolute value of -2 is abs(-2). This value is bigger than 0
>
> Most people think it a mistake to confuse data and code.
>
> If you were determined, you could do so. You might parse the string and
> use eval on bits that look like functions. I'd reconsider.
>
> --
> RGB
Interesting, but how do i know how a function does look like
what is if i have a string
"blah (a,b,c)"
Is this a function ?
Is it a normal list ?
------------------------------
Date: Tue, 20 Jan 2009 16:57:12 +0000
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: function calls in double quoted strings
Message-Id: <4976026a$0$30298$da0feed9@news.zen.co.uk>
david wrote:
> RedGrittyBrick wrote:
>> david wrote:
>>> Josef Moellers wrote:
>>>> david wrote:
>>>>>
>>>>> HI all,
>>>>> This is more a question out of curiosity. Is it possible to call a
>>>>> function from a double quoted string. For example
>>>>> print "The absolute value of -2 is abs(-2). This value is bigger than
>>>>> 0"
>>>>
>>>> Have you tried it? What happened? The earth collapsed? Bush got another
>>>> term in office?
>>>
>>> something much more dramatic:
>>> This is the print text:
>>> The absolute value of -2 is abs(-2). This value is bigger than 0
>>
>> Most people think it a mistake to confuse data and code.
>>
>> If you were determined, you could do so. You might parse the string and
>> use eval on bits that look like functions. I'd reconsider.
>
> Interesting, but how do i know how a function does look like
Good question. How do *you* know? (only *you* can answer that). Once
*you* have decided how, *you* can write Perl code to implement *your*
method. After that, I expect this newsgroup will be of more help.
> what is if i have a string
> "blah (a,b,c)"
> Is this a function ?
> Is it a normal list ?
I'd say it can be either, both or neither. Written languages are often
ambiguous. This is one reason why I think writing a compiler must be
non-trivial.
Where did your double quoted strings originate? Did you write them? Did
someone else write them? Did they follow some convention? Could you
rewrite them to follow an unambiguous convention?
IME hard problems rarely have easy solutions. Easy solutions to hard
problems might sometimes just underestimate their difficulty.
--
RGB
------------------------------
Date: Tue, 20 Jan 2009 11:00:35 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: function calls in double quoted strings
Message-Id: <slrngnc0pj.sp.tadmc@tadmc30.sbcglobal.net>
david <michaelgang@gmail.com> wrote:
> This is more a question out of curiosity.
There are many curious folks.
Your Question is Asked Frequently.
> Is it possible
Possible? Yes.
A good idea? Probably not.
> to call a
> function from a double quoted string.
perldoc -q function
How do I expand function calls in a string?
> For example
> print "The absolute value of -2 is abs(-2). This value is bigger than
> 0"
If "abs(-2)" was automagically replaced with "2", then you
would not be able to print that 7-character string.
ie. If "data" was "code", then:
print "use abs(-2) to find the absolute value of -2\n"
would output
use 2 to find the absolute value of -2
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 20 Jan 2009 12:45:53 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: function calls in double quoted strings
Message-Id: <86d4ehg6ji.fsf@lifelogs.com>
On Tue, 20 Jan 2009 07:31:50 -0800 (PST) david <michaelgang@gmail.com> wrote:
d> This is more a question out of curiosity. Is it possible to call a
d> function from a double quoted string. For example
d> print "The absolute value of -2 is abs(-2). This value is bigger than
d> 0"
d> I know i can use sprintf or write the string like this
d> print 'The absolute value of -2 is '.abs(-2).'. This value is bigger
d> than 0'
Yes:
print "The absolute value of -2 is @{[ abs(-2) ]}. This value is bigger than 0\n";
You can put any Perl code in there, but I wouldn't.
Ted
------------------------------
Date: Tue, 20 Jan 2009 11:09:16 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: function calls in double quoted strings
Message-Id: <slrngnc19s.11k.tadmc@tadmc30.sbcglobal.net>
david <michaelgang@gmail.com> wrote:
> On Jan 20, 6:23pm, RedGrittyBrick <RedGrittyBr...@spamweary.invalid>
> wrote:
>> Most people think it a mistake to confuse data and code.
Not snipped, because it appears to have been skipped... :-(
> Interesting, but how do i know how a function does look like
> what is if i have a string
^^^^^^^^^^^^^^^
> "blah (a,b,c)"
> Is this a function ?
> Is it a normal list ?
You said yourself that it is a string.
A string is not a function.
A string is not a list.
So ""blah (a,b,c)" is ... a string!
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 20 Jan 2009 09:09:44 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: inputting the ephemerides
Message-Id: <tzndl.166146$2w3.85645@newsfe19.iad>
George wrote:
> On Mon, 19 Jan 2009 23:08:09 -0800, Tim Greer wrote:
>
>> J�Exner wrote:
>>
>>> You know, this is terribly similar to something I have seen a few
>>> weeks ago from some George character
>>
>> He was George, said he was changing his posting name in celebration
>> of
>> George being out of office. I also can't wrap my head around his
>> example of posting code that opens a file and prints and then another
>> snippet basically being the same, just without error checking.
>> Weird. I stopped reading and moved on.
>
> Between the responses no source survived, so you can't wonder too much
> why context is a problem.
>
> Here's the resolution of your "weirdness:"
>
> my $filename = 'eph3.txt';
> open(my $fh, '<', $filename) or die "cannot open $filename: $!";
>
> while (my $line = <$fh>){
>
> print $line;
> }
> close($fh)
>
> # perl faulk11.pl
I saw your original post (I don't have you blocked). You posted a
portion of code, such as above, that goes through each line and prints
it. It's not really doing anything related to the task you asked
about. What was "weird" was that you posted the same code again (for
the most part), but just failed to check the return value of open and
didn't add $_ to print (since it wouldn't be needed -- it wasn't in the
first one either). I fail to understand the purpose of you doing that?
You then posted about what you wanted to do, but you didn't post any
code relevant to it to show us what you have tried. I admit, I thought
that was weird.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
Date: Tue, 20 Jan 2009 10:39:23 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: inputting the ephemerides
Message-Id: <200120091039238728%jimsgibson@gmail.com>
In article <1x83tkcjxizri.7vvnwjo82ona$.dlg@40tude.net>, Larry Gates
<larry@example.invalid> wrote:
> This is the data set:
>
> C:\MinGW\source>type eph3.txt
> ! yesterday
> # another comment
>
> Sun 18h 41m 55s -23 5.4' 0.983 10.215 52.155 Up
> Mercury 20h 2m 16s -22 12.5' 1.102 22.537 37.668 Up
> Venus 21h 55m 33s -14 16.3' 0.795 39.872 11.703 Up
> Moon 21h 17m 19s -15 2.4' 62.4 ER 36.796 22.871 Up
> Mars 18h 11m 59s -24 6.1' 2.431 4.552 56.184 Up
> Jupiter 20h 3m 35s -20 49.4' 6.034 23.867 38.203 Up
> Saturn 11h 32m 59s +5 8.6' 9.018 -47.333 157.471 Set
> Uranus 23h 21m 30s -4 57.9' 20.421 48.328 -18.527 Up
> Neptune 21h 39m 30s -14 22.8' 30.748 38.963 16.599 Up
> Pluto 18h 4m 34s -17 44.5' 32.543 7.443 62.142 Up
>
> C:\MinGW\source>
>
> Thanks for your comment.
You can use the unpack function to unpack data lines with fixed-length
columns like your example. See 'perldoc -f unpack' for details, and
'peldoc -f pack' for template parameters. Note that the A parameter
will cause Perl to trim trailing blanks on unpacking.
Something like
my( $name, $hour, $min, $sec, ... ) =
unpack('A8 A4 A4 A4 ... ',$line);
should work.
--
Jim Gibson
------------------------------
Date: Tue, 20 Jan 2009 20:08:02 GMT
From: sln@netherlands.com
Subject: Re: Match CASE/END SQL Construct
Message-Id: <04acn4hk26b7mim6rqe20qktm2im4d6bs1@4ax.com>
On Thu, 15 Jan 2009 15:05:29 -0500, "Perry Aynum" <jc_va@hotmail.com> wrote:
>I am working on a SQL parser. I have a routine that recursively removes
>enclosing parentheses and it works fine. Below is the regex that I use.
>
>However, I want to use the same routine, but instead of looking for
>enclosing parens, I want to look for a string enclosed by CASE and END. Can
>someone help me translate the regex below so that it will match a CASE/END
>construct?
>
>Thanks very much.
>
>Parens
>----------
>(?:\s+)?\([^\(\)]*\)
>
>
>
>This is what I've managed so far with the CASE/END
>
>(?:\s+)?case(?!case|end)\s+end
>
I've revisited this, became intrigued with zero-assertion width
extented regexp constructs. These constructs don't get enough air-time
here. Since you appear to be leaning in that direction, I thought I would
flesh out a look ahead regexp for your example, perhaps to try to glean insight on
the regexp engine, not really sure. Its very facinating for me. I'm not a big book
reader since I am dislexic, so I try to discover things on my own.
The below would seem to tackle your problem from the perspective of a file slurped
into a variable which is processed. All relavent delimeters are taken into acccount,
my other penchant is for parsing. It is possible to buffer line by line file info
until we just have enough to parse. I didn't do it of course but it is fairly easy.
This would aviod sucking up huge amounts of memory, and is fairly trivial once the
master regexp is known.
I've learned some stuff about the regexp engine's extended operations. I won't go into it.
I decided to include the progression of guesses that went into settling on its final form.
Obviously this form does take into account several delimiting factors as well as look-ahead.
Its not fully tested of course, but it passes my initial alpha form that could be
presented to testers.
As it is now, CASE/END are the targets, however, any can be substituted.
Should you like to employ me for extended projects, set up a contact arangement.
Note the code is at the bottom, the output is at the top, in true dyslexic fashion.
Particularly note in the output, how inner to outter matching goes. This is key.
sln
__OUTPUT__
c:\temp>perl misc9.pl
<<<<<<<<<<< Phase1 >>>>>>>>>>>
$1= --------
' case'
$txt= --------
'
case
1 case end
2 case case end end
fricases can erupt even among friends
end'
<<<<<<<<<<< Phase2 >>>>>>>>>>>
$1= --------
''
$txt= --------
'
case
1
2 case case end end
fricases can erupt even among friends
end'
<<<<<<<<<<< Phase3 >>>>>>>>>>>
$1= --------
''
$txt= --------
'
case
1
2 case end
fricases can erupt even among friends
end'
<<<<<<<<<<< Phase4 >>>>>>>>>>>
$1= --------
''
$txt= --------
'
case
1
2
fricases can erupt even among friends
end'
<<<<<<<<<<< Phase5 >>>>>>>>>>>
$1= --------
'
1
2
fricases can erupt even among friends'
$txt= --------
'
1
2
fricases can erupt even among friends'
************************
FINAL:
'
1
2
fricases can erupt even among friends'
c:\temp>
__CODE__
use strict;
use warnings;
my $txt = join '', <DATA>;
{
# while ($txt =~ s/(?:\s+|^)case(?=\s)(.*)(?!case)(?<=\s)end(?:\s+|$)/$1/is) {} <- sick
# while ($txt =~ s/(?:\s+)case(?=\s)(.*)(?!case)(?<=\s)end(?:\s+)/$1/is) { print "--------\n'$1'\n"} <- disgusting
# while ($txt =~ s/(?:\s+)case(?=\s)(.(?!case)*?)(?<=\s)end(?:\s+)/$1/is) { print "--------\n'$1'\n"} <- putrid
# while ($txt =~ s/(?:\s+)case(?=\s)((?<!case).*?)(?<=\s)end(?:\s+)/$1/is) { print "--------\n'$1'\n"} <- DOA
# while ($txt =~ s/\s+case\s+(.*(?!case))\s+end\s+/ $1 /is) <- what's this?
# while ($txt =~ s/\s+case\s+((.(?!case))*?)end\s+/ $1 /is) <- almost
# while ($txt =~ s/\s+case\s+((.(?!\scase\s))*?)\s+end\s+/ $1 /is) <- better
# while ($txt =~ s/\s+case((.(?!\scase\s))*?)\s+end\s+/ $1 /is) <- more better
# while ($txt =~ s/\s+case((.(?!\scase\s))*?)\s+end\s+/ $1/is) <- hmmm
# while ($txt =~ s/\s+case((.(?!\scase\s))*?)\s+end(\s+)/ $1 /is) <- confused
# while ($txt =~ s/\s+case((?:.(?!\scase\s))*?)\s+end(\s+)/$1$2/is) <- approaching excellence
# while ($txt =~ s/\s+case((?:.(?!\scase\s))*?)\s+end(\s+)/$1$2/is) <- excellence
# while ($txt =~ s/(?:\s+|^)case((?:.(?!\scase\s))*?)\s+end(\s+|$)/$1$2/is) <- PRIMO !!!!
my $cntr = 1;
while ($txt =~ s/(?:\s+|^)case((?:.(?!\scase\s))*?)\s+end(\s+|$)/$1$2/is) # <- Production Regex, Ship to QA
{
print "\n<<<<<<<<<<< Phase".$cntr++." >>>>>>>>>>>\n";
print "\$1= --------\n'$1'\n";
print "\$txt= --------\n'$txt'\n";
}
print "\n\n************************\n FINAL:\n'$txt'\n";
}
__DATA__
case
1 case case end end
2 case case end end
fricases can erupt even among friends
end
------------------------------
Date: Tue, 20 Jan 2009 08:43:05 -0800
From: Ken Teague <"kteague at pobox dot com">
To: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: unable to open file
Message-Id: <QNidnSQd5rbYYujUnZ2dnUVZ_u6dnZ2d@giganews.com>
RedGrittyBrick wrote:
> If your script is in P:\CGI-BIN and your Script's working directory is
> in C:\WINDOWS neither of these pieces of information will aid you much
> in accessing a data file in Z:\foo.dat. You have to use an absolute
> pathname to refer to the file.
That's what I was afraid off. What is the best way to have the script
find my data files in the same directory the script is in without
defining an absolute path?
> The location of your script is rarely helpful since usually it is more
> secure to keep data files in locations completely separate from that of
> executable scripts.
Please excuse my ignorance again, but why is it more secure? The
directory that contains the script also contains an HTML file which is
fed information provided by my script and a flat-file database text file
that contains product information. In my situation, I don't think that
either of those files contain data that needs to be private.
Thank you all for your input.
- Ken
------------------------------
Date: Tue, 20 Jan 2009 10:52:59 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: unable to open file
Message-Id: <slrngnc0bb.sp.tadmc@tadmc30.sbcglobal.net>
Ken Teague <"kteague at pobox dot com"> wrote:
> Tad J McClellan wrote:
>> What is your current working directory?
>
> I created this script and placed it in my cgi-bin directory:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use Cwd;
>
> print "Content-type:text/html\r\n\r\n";
> print '<html>';
> print '<head>';
> my $dir = getcwd;
> print "$dir", "\n";
> print '</body>';
> print '</html>';
>
> I hope this gives us the information we're looking for.
>
> I loaded it in my browser. It reveals:
> C:/WINDOWS
Good.
After you do
chdir 'C:/WINDOWS' or die "could not cd to 'C:/WINDOWS' $!";
you will be able to use a path that is relative to C:/WINDOWS.
> Please excuse me for my ignorance, but how can the drive/directory that
> my script is in not be relevant when we're dealing with a file system
> that has drive letters and the directory that contains the script is on
> a different drive letter than that of my current working directory?
Me no speaky "drive letters".
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 20 Jan 2009 11:43:29 -0800
From: Ken Teague <"kteague at pobox dot com">
Subject: Re: unable to open file
Message-Id: <dcadnT67yfT-tOvUnZ2dnUVZ_j6dnZ2d@giganews.com>
Tad J McClellan wrote:
> Good.
>
> After you do
>
> chdir 'C:/WINDOWS' or die "could not cd to 'C:/WINDOWS' $!";
>
> you will be able to use a path that is relative to C:/WINDOWS.
But the path to my script doesn't reside anywhere relative to C:/WINDOWS.
> Me no speaky "drive letters".
Going back to what you stated in your second reply to me:
> Where the perl binary is installed is not relevant to relative paths.
>
> Where your Perl program is installed is not relevant to relative
> paths.
>
> What is relevant to relative paths is your current working directory.
>
> What is relevant to relative paths is your current working directory.
>
> What is relevant to relative paths is your current working directory.
How is it not relevant when we're dealing with perl installed on an OS
that has a non-posix file system? Seems to me that it is relevant if
the two reside on different volumes, and different volumes are denoted
by "drive letters".
However, after finding this:
http://www.rcbowen.com/imho/perl_cwd_iis.html
and hashing out the issue on private list, we came up with this small
piece of code which solves my issue:
(my $dir = $0) =~ s:[\\/][^\\/]+$::;
chdir $dir or die "Can't change to directory $dir: $!\n";
Here is his reply to me, if anyone is interested:
> Hypothetically, the following line (inserted at the beginning of the
> script) should work:
>
> (my $dir = $0) =~ s:[\\/][^\\/]+$::;
> chdir $dir or die "Can't change to directory $dir: $!\n";
>
> However, it relies on the assumptions that the path to the script is
> given to Perl on the command line (instead of piping the script to
> Perl on standard input) and that changing the current working
> directory is allowed. I wouldn't put it past Microsoft to foul up
> one or both of those things.
Thanks again to everyone who contributed to this thread. :-)
- Ken
------------------------------
Date: Tue, 20 Jan 2009 11:05:33 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: unable to open file
Message-Id: <slrngnc12t.11k.tadmc@tadmc30.sbcglobal.net>
Ken Teague <"kteague at pobox dot com"> wrote:
> RedGrittyBrick wrote:
> > If your script is in P:\CGI-BIN and your Script's working directory is
>> in C:\WINDOWS neither of these pieces of information will aid you much
>> in accessing a data file in Z:\foo.dat. You have to use an absolute
>> pathname to refer to the file.
>
> That's what I was afraid off. What is the best way to have the script
> find my data files in the same directory the script is in without
> defining an absolute path?
By using a relative path, and forcing your cwd to be the same as
the directory where your script is.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 20 Jan 2009 10:53:57 -0800 (PST)
From: DJ Stunks <DJStunks@gmail.com>
Subject: use hash to name params, then stringify values in specific order
Message-Id: <813d1773-8533-4439-a578-4a7c30507c6d@f40g2000pri.googlegroups.com>
Hey all,
I have an API I need to call as a string of comma separated values. I
want to name those values in a hash so that it's easy to see what I'm
setting each value to. However, the values have to go into the API
call in a certain order. The goal is to make the code as clean and as
self-documenting as possible (ideally both the API call syntax and the
call values should be clearly apparent in the Perl code)
I can do it using a hash slice as follows, but this seems like a
pretty bad approach so I thought I'd shop it around and see what you
all think would be a better approach. Tie::IxHash maybe? (I've never
used it)
TIA,
-jp
#/usr/bin/perl
use strict;
use warnings;
#API syntax: my_API_call
(<this_parameter>,<that_parameter>,<extra_parameter>)
my %parms = (
this_parameter => 'some value',
that_parameter => 'another value',
extra_parameter => 'a third value',
);
my @order = qw{ this_parameter that_parameter extra_parameter };
my $stringified_API_call = 'my_API_call(' . join(',', @parms
{ @order }) . ')';
print "call it: $stringified_API_call\n";
__END__
------------------------------
Date: Tue, 20 Jan 2009 08:11:54 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: What do you need to have to be considered a Master at Perl?
Message-Id: <86wscqot2t.fsf@blue.stonehenge.com>
>>>>> "Tad" == Tad J McClellan <tadmc@seesig.invalid> writes:
Tad> 2) What is returned by mystery_func()?
Tad> sub mystery_func {
Tad> my @ra = 4;
Tad> push @ra, 2+3;
Tad> $ra[@ra] = 6;
Tad> return @ra;
Tad> }
Tad> I'll leave what is taken to be "the correct answer" as an
Tad> exercise for the reader...
Depends on whether it's called in a scalar or list context. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Tue, 20 Jan 2009 10:44:16 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: What do you need to have to be considered a Master at Perl?
Message-Id: <slrngnbvr0.sp.tadmc@tadmc30.sbcglobal.net>
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Tad" == Tad J McClellan <tadmc@seesig.invalid> writes:
>
>Tad> 2) What is returned by mystery_func()?
>
>Tad> sub mystery_func {
>Tad> my @ra = 4;
>Tad> push @ra, 2+3;
>Tad> $ra[@ra] = 6;
>Tad> return @ra;
>Tad> }
>
>Tad> I'll leave what is taken to be "the correct answer" as an
>Tad> exercise for the reader...
>
> Depends on whether it's called in a scalar or list context. :)
spoiler!
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 20 Jan 2009 10:49:17 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: What do you need to have to be considered a Master at Perl?
Message-Id: <slrngnc04d.sp.tadmc@tadmc30.sbcglobal.net>
Vicky Conlan <comps@riffraff.plig.net> wrote:
> According to <tadmc@seesig.invalid>:
>>1)
>> What is the difference between my() and our()?
>
> IMHO, /my/ correct answer here would be "can I borrow your computer
> for a minute to check in perldoc, please?"
The correct answer should discuss the differences between
lexical variables and package variables.
> (having never actually come across our() before - thanks for giving
> me something to print out and read on the way home, btw ;-)
> On first glance, I can see the difference,
As above, the difference is really the difference in Perl's
two completely separate variable systems.
> but I'm failing to see a
> real advantage or purpose to our().
If you happen to be in a situation where package variables
are required, then our()'s only real purpose is to make
"use strict" shut up when you choose to use the "short" name
for the package variable.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 20 Jan 2009 09:14:27 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: What do you need to have to be considered a Master at Perl?
Message-Id: <TDndl.166148$2w3.114060@newsfe19.iad>
Vicky Conlan wrote:
>>In both exams, I placed in the top quintile, which surprised me very
>>much. In both cases, I had made it through two rounds of interviews.
>>My take is that there must be a lot of people who claim to know Perl
>>but maybe they don't.
>
> Having marked Perl tests a few times in the last year or two, I'm not
> at all surprised you scored higher than you expected.
...
To be honest, most of the "tests" I've seen people have to take, are
very, very rudimentary. I'd hate to think someone took a basic test,
scored high and thought this might mean they are an expert at a
language they've only just started really learning. If they get the
job and can perform the tasks, and are willing to accept they always
have more to learn, then that's great.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
Date: Tue, 20 Jan 2009 12:21:21 -0800 (PST)
From: cartercc <cartercc@gmail.com>
Subject: Re: What do you need to have to be considered a Master at Perl?
Message-Id: <e1adbe86-8495-42d6-abc7-82e62a599056@w34g2000yqm.googlegroups.com>
On Jan 20, 12:14=A0pm, Tim Greer <t...@burlyhost.com> wrote:
> To be honest, most of the "tests" I've seen people have to take, are
> very, very rudimentary. =A0I'd hate to think someone took a basic test,
> scored high and thought this might mean they are an expert at a
> language they've only just started really learning. =A0If they get the
> job and can perform the tasks, and are willing to accept they always
> have more to learn, then that's great.
Of the two tests I've taken, one was a programming test of three
programs with an hour to complete. The first two were pretty simple.
The third was more difficult, mostly due to the problem set rather
than language issues. I missed a significant portion of the third
question due to a misreading of the specification.
The second test was an objective test, and I thought it was a pretty
good measure of knowledge. I normally have a very poor opinion of
objective tests, but this one was a work-out. I did pretty well on it
but attribute it to a combination of luck and inspired guessing.
I believe that these kinds of tests are a good idea for employers as
long as their purpose is to weed out imposters. I don't think that
they do a good job of measuring proficiency from the standpoint that a
person's experience in writing a KIND of script says nothing about his
aptitude. (A test focusing on file manipulation might catch a person
who excels at writing sys admin scripts, and would reveal nothing
about his aptitude in general.)
CC
------------------------------
Date: Tue, 20 Jan 2009 20:35:06 GMT
From: sln@netherlands.com
Subject: Re: What do you need to have to be considered a Master at Perl?
Message-Id: <e9dcn49asmt311t0bq3n8vkpe3e6t4r3lg@4ax.com>
On Tue, 20 Jan 2009 08:11:54 -0800, merlyn@stonehenge.com (Randal L. Schwartz) wrote:
>>>>>> "Tad" == Tad J McClellan <tadmc@seesig.invalid> writes:
>
>Tad> 2) What is returned by mystery_func()?
>
>Tad> sub mystery_func {
>Tad> my @ra = 4;
>Tad> push @ra, 2+3;
>Tad> $ra[@ra] = 6;
>Tad> return @ra;
>Tad> }
>
>Tad> I'll leave what is taken to be "the correct answer" as an
>Tad> exercise for the reader...
>
>Depends on whether it's called in a scalar or list context. :)
Right, what you you expect from somebody who doesen't know the difference
between a program written in C++ or a C++ program.
sln
------------------------------
Date: Tue, 20 Jan 2009 15:50:22 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: What do you need to have to be considered a Master at Perl?
Message-Id: <86bpu11z3l.fsf@mithril.chromatico.net>
>>>>> "TJM" == Tad J McClellan <tadmc@seesig.invalid> writes:
TJM> Vicky Conlan <comps@riffraff.plig.net> wrote:
>> According to <cartercc@gmail.com>:
>>> My take is that there must be a lot of people who claim to know
>>> Perl but maybe they don't.
TJM> This is absolutely true. I've seen it many many times.
It's common everywhere. It's very easy for a programmer to know enough
Perl to bamboozle a recruiter or HR person, and to be able to talk his
or her way through a phone screening interview.
My current company has a Perl test that touches on algorithms and data
structures, interaction with the user via CGI, and interaction with
databases via DBI. It's a problem that realistically should take a
competent programmer about two hours to finish, and the candidate is
told this and given an hour, so that we can see how far he or she gets
and what the partial solution looks like. This is very useful
information, even though (as I can attest, having taken the test myself)
it is stressful.
Then discussion of the problem and how far the candidate got and what
the more efficient solutions might be is more elucidating.
And we have a list of interview questions that elucidate weak points --
like the difference between defined and exists, or the difference
between system and exec.
TJM> Two of the test questions that I like to use in interviews:
TJM> 1) What is the difference between my() and our()?
TJM> (followup if they get that right: What about local()?)
TJM> (followup if they have still not eliminated themselves: When
TJM> would you use one over the other?)
We use a variant of this -- we ask about the difference between my, our,
and local.
TJM> 2) What is returned by mystery_func()?
TJM> sub mystery_func { my @ra = 4; push @ra, 2+3; $ra[@ra] = 6;
TJM> return @ra;
TJM> }
TJM> I'll leave what is taken to be "the correct answer" as an
TJM> exercise for the reader...
That one threw me for a loop until I realized I was mentally filling in
a @ for the $ because there was a @ inside the brackets....
One of my favorites:
You have a string that comes from a freeform text field where the user
is expected to enter a telephone number. Write a regular expression to
validate it and capture a usable phone number.
This is usually good for a lot of discussion about what should be valid,
and about the damnfool things that users do. It also shows whether the
candidate has a grasp of basic regular expressions: programmers who are
comfortable with them usually try to figure out what foolish things a
user is likely to do, while programmers who are not comfortable with
them usually try to remember what the syntax is for capturing.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
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 2142
***************************************