[25436] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7681 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 21 18:05:31 2005

Date: Fri, 21 Jan 2005 15:05:13 -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           Fri, 21 Jan 2005     Volume: 10 Number: 7681

Today's topics:
    Re: "Can't modify non-lvalue subroutine call" furrows m <rick@rickcasey.net>
    Re: "Can't modify non-lvalue subroutine call" furrows m (Anno Siegel)
    Re: "Can't modify non-lvalue subroutine call" furrows m <rick@rickcasey.net>
    Re: "Can't modify non-lvalue subroutine call" furrows m <1usa@llenroc.ude.invalid>
    Re: "Can't modify non-lvalue subroutine call" furrows m (Anno Siegel)
    Re: "Can't modify non-lvalue subroutine call" furrows m <mritty@gmail.com>
        any example of how Net::Jabber::Log should be used? <bdu@iastate.edu>
        Electronic Medical Records : recommendation of open sou drleeds@gmail.com
        File::Find gives me current dir (.)? <ben.rogers@gmail.com>
    Re: net::SFTP to capture 'get' reference? <nobull@mail.com>
    Re: net::SFTP to capture 'get' reference? <rhxk@yahoo.com>
    Re: Perl and waiting for execution of external program (Anno Siegel)
    Re: Perl and waiting for execution of external program <1usa@llenroc.ude.invalid>
    Re: Perl and waiting for execution of external program (Anno Siegel)
        Perl on Windows <adamsmith@econ.com>
    Re: Perl on Windows <1usa@llenroc.ude.invalid>
    Re: Perl on Windows <spamtrap@dot-app.org>
    Re: Perl on Windows binnyva@hotmail.com
    Re: Perl on Windows <1usa@llenroc.ude.invalid>
    Re: Perl on Windows <spamtrap@dot-app.org>
    Re: Perl script issues - Need help <georgemj@sympatico.ca>
        Preserve Timestamp pulsar4f@hotmail.com
    Re: Preserve Timestamp (Anno Siegel)
    Re: Radix Sort in CPAN (Anno Siegel)
    Re: Radix Sort in CPAN <1usa@llenroc.ude.invalid>
    Re: regular expressions (Anno Siegel)
    Re: saying my $a=0; my $b=0; more compactly <dwilga-MUNGE@mtholyoke.edu>
        Sorting an Array by Another (Binny V A)
    Re: Sorting an Array by Another drleeds@gmail.com
    Re: Sorting an Array by Another xhoster@gmail.com
    Re: Sorting an Array by Another (Anno Siegel)
    Re: Sorting an Array by Another drleeds@gmail.com
    Re: Whats the variable holding the dir seperator? (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 21 Jan 2005 11:27:30 -0800
From: "rickcasey" <rick@rickcasey.net>
Subject: Re: "Can't modify non-lvalue subroutine call" furrows my brow
Message-Id: <1106335650.621286.87060@f14g2000cwb.googlegroups.com>

Thanks for these replies; most were informative (though replies like
Mr. Unur's are so cryptic they do not help at all). Sorry I failed to
say what exactly I modified; here's what I did:

All I did was to add the elsif branch to the end of the if/else
statement in this subroutine (i.e., the code after
} elsif ($db_type eq "Pg") {

I did not modify how the subroutine is called, or the return statement.


My code does modify what is returned by the subroutine, which is
created in the foreach loop just before the subroutine ends. Now I am
thinking that I need to modify the values in the %quoted_types hash --
because if they are not correct, the %quotable hash will not get
assigned correctly. Could that possibly be the cause of the error?
Thanks, rick



------------------------------

Date: 21 Jan 2005 19:51:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: "Can't modify non-lvalue subroutine call" furrows my brow
Message-Id: <csrmfj$r8n$1@mamenchi.zrz.TU-Berlin.DE>

rickcasey <rick@rickcasey.net> wrote in comp.lang.perl.misc:
> Thanks for these replies; most were informative (though replies like
> Mr. Unur's are so cryptic they do not help at all). Sorry I failed to
> say what exactly I modified; here's what I did:
> 
> All I did was to add the elsif branch to the end of the if/else
> statement in this subroutine (i.e., the code after
> } elsif ($db_type eq "Pg") {
> 
> I did not modify how the subroutine is called, or the return statement.

That is hard to swallow.  If the *only* change is the one you describe,
the critical line would have been called before and after the change,
and it would have failed for the same reason.  Something else must be
going on.

Anno


------------------------------

Date: 21 Jan 2005 12:50:44 -0800
From: "rickcasey" <rick@rickcasey.net>
Subject: Re: "Can't modify non-lvalue subroutine call" furrows my brow
Message-Id: <1106340644.754144.73480@c13g2000cwb.googlegroups.com>

You are right; something else was going on.

I was fortunate enough to get a reply from one of the original
programmers of this application, and he said just delete the line
causing the error, i.e. 1159. I did that, and the code worked.

Why Perl was producing that error message is still a mystery, but a
moot point now....

rick



------------------------------

Date: 21 Jan 2005 21:01:32 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: "Can't modify non-lvalue subroutine call" furrows my brow
Message-Id: <Xns95E5A30BA6DA3asu1cornelledu@132.236.56.8>

"rickcasey" <rick@rickcasey.net> wrote in news:1106340644.754144.73480
@c13g2000cwb.googlegroups.com:

> Why Perl was producing that error message is still a mystery, but a
> moot point now....

There was no mystery.

Sinan.


------------------------------

Date: 21 Jan 2005 21:05:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: "Can't modify non-lvalue subroutine call" furrows my brow
Message-Id: <csrqqa$t60$3@mamenchi.zrz.TU-Berlin.DE>

rickcasey <rick@rickcasey.net> wrote in comp.lang.perl.misc:

> You are right; something else was going on.

Please give an attribution and quote some context when replying.  This
way nobody knows what you are talking about.

> I was fortunate enough to get a reply from one of the original
> programmers of this application, and he said just delete the line
> causing the error, i.e. 1159. I did that, and the code worked.
> 
> Why Perl was producing that error message is still a mystery, but a
> moot point now....

No, the reason for the error message is very clear: ->errstr (or what
it's called) is not an lvalue method.  The mystery is why the line
was there in the first place, and why it didn't trigger the error
before.

Anno


------------------------------

Date: Fri, 21 Jan 2005 21:05:19 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: "Can't modify non-lvalue subroutine call" furrows my brow
Message-Id: <j8eId.9401$Dz2.4297@trndny09>

"rickcasey" <rick@rickcasey.net> wrote in message
news:1106340644.754144.73480@c13g2000cwb.googlegroups.com...
> You are right; something else was going on.
>
> I was fortunate enough to get a reply from one of the original
> programmers of this application, and he said just delete the line
> causing the error, i.e. 1159. I did that, and the code worked.
>
> Why Perl was producing that error message is still a mystery, but a
> moot point now....

Did you read *any* of the replies in this thread?  How can you call that
a mystery?!

Paul Lalli



------------------------------

Date: Fri, 21 Jan 2005 16:34:15 -0600
From: bingster <bdu@iastate.edu>
Subject: any example of how Net::Jabber::Log should be used?
Message-Id: <35deb8F4jffjlU1@individual.net>

Our jabber server saves the logs in xml format.  I'm installed the 
Net::Jabber::Log and hope it can convert the log from xml format to some 
other easy to browse format, like plain text.  Is Net::Jabber::Log the 
right module to do this?  I've looked at its manual but cannot figure 
out how to use it since no examples are given in the manual.  Anybody 
with some experience with Net::Jabber::Log would like to shed some light 
on how this module should be used?  Thanks in advance for any help.

Bing


------------------------------

Date: 21 Jan 2005 12:06:26 -0800
From: drleeds@gmail.com
Subject: Electronic Medical Records : recommendation of open source software?
Message-Id: <1106337986.790060.208930@c13g2000cwb.googlegroups.com>

I am looking for an open source project written in Perl for Electronic
Medical Records.

There are several big names that are written in PHP and I did note a
few useful modules at cpan.org, but I am curious to see what has been
done in Perl that I could modify for my own purposes instead of wasting
time and effort building something from the ground up.
Thank you for your help,

drleeds@gmail.com



------------------------------

Date: 21 Jan 2005 15:01:58 -0800
From: "ben.rogers@gmail.com" <ben.rogers@gmail.com>
Subject: File::Find gives me current dir (.)?
Message-Id: <1106348518.358793.22010@f14g2000cwb.googlegroups.com>

I wrote a  subroutine that finds all of the files of a certain type.
For example, if I want to find all .fm and .book files, I push these
file types to @file_types and send that to File::Find or to grep to get
my list of files (depending on whether the search should be recursive.

I print that list as shown below. Note that I get:

Open
Convert mif
Close

I haven't been able to get rid of this. Am I getting the current dir
(.) or something?

thanks for any advice,

b



################################# FIND FILES
# Print instructions for finding files to the script created by
createScriptFile.
# Get the input directory ($inputdir) and recursion setting ($recursion
= 1 or 0).
# Get the file types (@file_types) and make a string used by grep or
File::Find.
sub fileFinder {
my $file_match_string = join ("|", @file_types);
if ($recursive =~ 1) {
chdir "$inputdir";
find (\\&wanted, "$inputdir");
sub wanted(){
if (\$File::Find::name =~ /($file_match_string)\$/i && -f){
print STDOUT "FOUND: \$File::Find::name\\n";
push \@files, \$File::Find::name;
}
}
print STDOUT "Finished finding files.";
} else { # Just GREP and don't use recursion.
print "my \@files = '';\n";
print "opendir(DIR, \"$inputdir\");\n";
print "\@files = grep /$file_match_string/,";
print "readdir(DIR);\nclosedir(DIR);\n";
}
}


--------------- printed list of files -------------------------
Open
Convert mif
Close

Open C:\Adobe\mifaliscious\b4\deploying_projects.fm
Convert mif C:\Adobe\mifaliscious\b4\deploying_projects.fm
Close C:\Adobe\mifaliscious\b4\deploying_projects.fm

Open C:\Adobe\mifaliscious\b4\front.fm
Convert mif C:\Adobe\mifaliscious\b4\front.fm
Close C:\Adobe\mifaliscious\b4\front.fm

Open C:\Adobe\mifaliscious\b4\server.book
Convert mif C:\Adobe\mifaliscious\b4\server.book
Close C:\Adobe\mifaliscious\b4\server.book

Open C:\Adobe\mifaliscious\b4\serverIX.fm
Convert mif C:\Adobe\mifaliscious\b4\serverIX.fm
Close C:\Adobe\mifaliscious\b4\serverIX.fm



------------------------------

Date: Fri, 21 Jan 2005 19:03:44 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: net::SFTP to capture 'get' reference?
Message-Id: <csrjck$avn$1@sun3.bham.ac.uk>



Rob wrote:
> I'm sftp'ing files from one machine to this one, and wanted to 
> capture the error messages for the $sftp->get reference.
> 
> I tried the eval method, but that didn't work...any ideas?
> here's my script.

What version of Perl are you using.  I have seen cases in 5.6 where eval 
{} will trap an error and fail to set $@.  I don't thing I seen this 
happen in 5.8.



------------------------------

Date: Fri, 21 Jan 2005 20:36:15 GMT
From: Rob <rhxk@yahoo.com>
Subject: Re: net::SFTP to capture 'get' reference?
Message-Id: <3JdId.13899$5R.5529@newssvr21.news.prodigy.com>

Ah, sorry, perhaps I should have been more clear.

I'm running perl 5.8.0 on a redhat WS3 machine.
when I run the script, it prints the error message
to the STDOUT:
Couldn't stat remote file: No such file or directory at
/usr/lib/perl5/site_perl/5.8.0/Net/SFTP.pm line 130.

I want this in $x so I can call fx2txt funcion within
SFTP::Util pm.




Brian McCauley wrote:

> 
> 
> Rob wrote:
>> I'm sftp'ing files from one machine to this one, and wanted to
>> capture the error messages for the $sftp->get reference.
>> 
>> I tried the eval method, but that didn't work...any ideas?
>> here's my script.
> 
> What version of Perl are you using.  I have seen cases in 5.6 where eval
> {} will trap an error and fail to set $@.  I don't thing I seen this
> happen in 5.8.



------------------------------

Date: 21 Jan 2005 20:06:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl and waiting for execution of external program
Message-Id: <csrnc3$r8n$2@mamenchi.zrz.TU-Berlin.DE>

A. Sinan Unur <1usa@llenroc.ude.invalid> wrote in comp.lang.perl.misc:

> What is $803?

Ah, you know what it is.  Rarely defined, but valid.

Anno


------------------------------

Date: 21 Jan 2005 20:11:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl and waiting for execution of external program
Message-Id: <Xns95E59A88BF990asu1cornelledu@132.236.56.8>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in news:csrnc3$r8n$2
@mamenchi.zrz.TU-Berlin.DE:

> A. Sinan Unur <1usa@llenroc.ude.invalid> wrote in comp.lang.perl.misc:
> 
>> What is $803?
> 
> Ah, you know what it is.  Rarely defined, but valid.

It was more of a rhetorical question :) I was feeling very contemplative 
at the time.

Sinan.


------------------------------

Date: 21 Jan 2005 20:23:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl and waiting for execution of external program
Message-Id: <csrobc$r8n$3@mamenchi.zrz.TU-Berlin.DE>

A. Sinan Unur <1usa@llenroc.ude.invalid> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in news:csrnc3$r8n$2
> @mamenchi.zrz.TU-Berlin.DE:
> 
> > A. Sinan Unur <1usa@llenroc.ude.invalid> wrote in comp.lang.perl.misc:
> > 
> >> What is $803?
> > 
> > Ah, you know what it is.  Rarely defined, but valid.
> 
> It was more of a rhetorical question :) I was feeling very contemplative 
> at the time.

I can see that...

    $803? Oh, it should be 803, not $803.
    Wait, it shouldn't be hard-coded, it should be __LINE__.
    Ah, but then it shouldn't be there at all, die() or warn() do that better.

Quite some contemplation on a single variable :)

Anno


------------------------------

Date: Fri, 21 Jan 2005 11:43:23 -0800
From: Adam Smith <adamsmith@econ.com>
Subject: Perl on Windows
Message-Id: <8cudnR-XYvkdx2zcRVn-gA@speakeasy.net>

Hello,

Could anyone advise on HOW TO set up and run Perl scripts on windows, 
and is it possible to run them as "standalones" without a server / browser

Thanks

--  Adam  --


------------------------------

Date: 21 Jan 2005 19:56:30 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl on Windows
Message-Id: <Xns95E598053134Aasu1cornelledu@132.236.56.8>

Adam Smith <adamsmith@econ.com> wrote in
news:8cudnR-XYvkdx2zcRVn-gA@speakeasy.net: 

> Could anyone advise on HOW TO set up and run Perl scripts on windows, 

My preferred distribution is ActiveState's ActivePerl. You can download 
the latest version from:

http://www.activestate.com/Products/ActivePerl/

> and is it possible to run them as "standalones" without a server /
> browser 

Yes. The installation will ask to set up file associations for you. If you 
also add the extension you will be using for your scripts, such as .pl or 
 .plx to the PATHEXT variable, you can run scripts in your path without 
typing their extensions.

If you are not going to do any CGI programming, you will not need to set 
up a web server. However, if there is even the remotest possibility, you 
can get the Windows version of Apache from http://httpd.apache.org/.

Sinan.



------------------------------

Date: Fri, 21 Jan 2005 14:59:04 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Perl on Windows
Message-Id: <DsednTWVK6aXwmzcRVn-1g@adelphia.com>

Adam Smith wrote:

> Could anyone advise on HOW TO set up and run Perl scripts on windows,

    <http://www.activestate.com>

> and is it possible to run them as "standalones" without a server / browser

For help on getting started with Perl, have a look at:

    <http://learn.perl.org>

If you haven't done so already, please read the posting guidelines that
appear here twice a week. Lots of pointers and tips there.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


------------------------------

Date: 21 Jan 2005 12:06:22 -0800
From: binnyva@hotmail.com
Subject: Re: Perl on Windows
Message-Id: <1106337982.929119.253740@f14g2000cwb.googlegroups.com>

Dear Adam,

I have wrote a tutorial on Perl - the first page deals with the issue
at hand.
Check out the first page of the tutorial at
http://www.geocities.com/binnyva/code/perl/tutorial/index.html
Binny.
http://www.geocities.com/binnyva/code



------------------------------

Date: 21 Jan 2005 20:16:27 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl on Windows
Message-Id: <Xns95E59B672A375asu1cornelledu@132.236.56.8>

binnyva@hotmail.com wrote in news:1106337982.929119.253740
@f14g2000cwb.googlegroups.com:

> I have wrote a tutorial on Perl - the first page deals with the issue
> at hand.
> Check out the first page of the tutorial at
> http://www.geocities.com/binnyva/code/perl/tutorial/index.html
> Binny.
> http://www.geocities.com/binnyva/code

I didn't look at your code again, but have you addressed the issues 
already discussed in the thread from December 1, 2004:

http://tinyurl.com/3l2t2

Sinan.


------------------------------

Date: Fri, 21 Jan 2005 15:40:02 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Perl on Windows
Message-Id: <JMmdnSWG5-Y59WzcRVn-sA@adelphia.com>

A. Sinan Unur wrote:

> I didn't look at your code again, but have you addressed the issues
> already discussed in the thread from December 1, 2004:

I did. He hasn't. Adam - don't bother with this one. There are links to
*good* tutorials and other stuff on:

    <http://learn.perl.org>

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


------------------------------

Date: Fri, 21 Jan 2005 17:14:58 -0500
From: "George Monappallil" <georgemj@sympatico.ca>
Subject: Re: Perl script issues - Need help
Message-Id: <F9fId.46460$K03.1208757@news20.bellglobal.com>

Great tips. Thanks much. Would you know how I can have this script monitor a
log file continiously..like a daemon. Is it possible ?

-George


"Dave Weaver" <zen13097@zen.co.uk> wrote in message
news:41f0cca2$0$13376$fa0fcedb@news.zen.co.uk...
> George Monappallil <georgemj@sympatico.ca> wrote:
> >       if (/ERROR/|/WARNING/i) {
> >          print $_;
> >         }
>
> I don't think that's doing quite what you expected it to do.
>
> The '|' operator is a binary 'or'.
>
> Maybe you're thinking of the '||' (logical 'or') operator, in which
> case you want:
>
> if ( /ERROR/ || /WARNING/i ) {
>
> which is IMHO better written as:
>
> if ( /ERROR/ or /WARNING/i ) {
>
> (Note that you only have the "i" modifier on the one pattern
> match, so it won't match 'Error' but it will match 'Warning').
>
> Or maybe you're thinking of the regex alternation operator:
>
> if ( /ERROR|WARNING/i ) {
>
> (which *will* match 'Error' as well as 'Warning').
>
> Also, note that $_ is the default argument for print, so you
> could have written:
>
> if ( /ERROR|WARNING/i ) {
>     print;
> }
>
> or, more succinctly:
>
> print if /ERROR|WARNING/i;
>




------------------------------

Date: 21 Jan 2005 12:34:00 -0800
From: pulsar4f@hotmail.com
Subject: Preserve Timestamp
Message-Id: <1106339640.320288.46120@f14g2000cwb.googlegroups.com>

I'm try to search and replace a string in some files, but I don't want
the file's timestamp to change if it doesn't contain the string I'm
searching for.  Any ideas?



------------------------------

Date: 21 Jan 2005 20:58:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Preserve Timestamp
Message-Id: <csrqdj$t60$2@mamenchi.zrz.TU-Berlin.DE>

 <pulsar4f@hotmail.com> wrote in comp.lang.perl.misc:
> I'm try to search and replace a string in some files, but I don't want
> the file's timestamp to change if it doesn't contain the string I'm
> searching for.  Any ideas?

None needed, a little systematic search takes you right there.

See "perldoc perlfunc" and check the list headed "Functions for filehandles,
files, or directories".  One of the entries has the string "time" in it.
Take it from there.

Anno


------------------------------

Date: 21 Jan 2005 19:12:25 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Radix Sort in CPAN
Message-Id: <csrk6p$pen$1@mamenchi.zrz.TU-Berlin.DE>

Edward Wijaya <ewijaya@singnet.com.sg.removethis> wrote in comp.lang.perl.misc:
> On 21 Jan 2005 13:58:46 GMT, A. Sinan Unur <1usa@llenroc.ude.invalid>  
> wrote:
> 
> 
> Thanks so much for your notice, Sinan.
> 
> I really appreciate it. I have made the correction to the module under ver  
> 0.02.
> Hope it works ;-)

You *hope*?  Haven't you tested it?

Your two tests in t/Sort-Radix.t only test formalities.  You should at
least add one test that actually sorts an array.

Further, your sub radix_sort() fails silently when all the input strings
don't have the same length.  This fact is not in your documentation, it
is only mentioned in a source comment.  You should check the arguments
and either fail or do something about it.  In any case describe it.  That
would belong in the description part of your pod.  The explanation of the
algorithm that you have there belongs under a different heading.

Further, in the pod part, if you let lines begin with white space (as
you do), that tells pod to take that text literally and *not* format
it.  You don't want that, not with lines of over 100 characters.  Take
a look at your documentation before you publish it.

All in all, this looks like a *very* premature release.  Please don't
do that.

Anno


------------------------------

Date: 21 Jan 2005 20:02:52 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Radix Sort in CPAN
Message-Id: <Xns95E59919299C0asu1cornelledu@132.236.56.8>

"Edward Wijaya" <ewijaya@singnet.com.sg.removethis> wrote in
news:opskxpaftvavcff0@news.singnet.com.sg: 

> On 21 Jan 2005 13:58:46 GMT, A. Sinan Unur <1usa@llenroc.ude.invalid> 
> wrote:
> 
> 
> Thanks so much for your notice, Sinan.
> 
> I really appreciate it. I have made the correction to the module under
> ver  0.02.
> Hope it works ;-)

Given that your module is very very small, I think you and the Perl 
community would have been better off if you had put the code up some place 
and asked for comments from this newsgroup and comp.lang.perl.modules to 
get the module in better shape before putting it on CPAN.

Think about writing some good tests.

Sinan.


------------------------------

Date: 21 Jan 2005 21:51:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regular expressions
Message-Id: <csrths$1sk$1@mamenchi.zrz.TU-Berlin.DE>

Lars Eighner  <eighner@io.com> wrote in comp.lang.perl.misc:
> In our last episode, 
> <358n9nF4jap49U1@individual.net>, 
> the lovely and talented Sokar 
> broadcast on comp.lang.perl.misc:
> 
> > hi,
> 
> > I have the string
> 
> > $variable = ",1,2,3,4,5";
> 
> > I was wondering if anyone knew a regular expression that would remove the
> > first "," so that I would have

[...]

> general case well enough.  Do you mean:
> 
> a) remove the first character in a string,
> b) remove the first character in a string if it is a comma,
> c) remove the first comma in a string (whether it precedes
> another character or not),
> d) remove the first comma in a string only if it precedes a
> numeral,
> e) some other possibile interpretations of your requirements I
> haven't thought of.
> 
> and
> 
> Do you know the 1) the comma you want removed will always be
> there or 2) the comma you want removed may or may not be there?
> 
> > $variable = "1,2,3,4,5"

Thanks for the analysis.

An innocent, but carelessly worded question like the one up there can
open up a vast tree of alternatives.  They all must be considered before
you can even begin to think about a solution.  This is how the time
spent in answering is sometimes inverse exponential in proportion to
the time spent on stating the question.  It can get annoying...

Anno


------------------------------

Date: Fri, 21 Jan 2005 14:28:44 -0500
From: Dan Wilga <dwilga-MUNGE@mtholyoke.edu>
Subject: Re: saying my $a=0; my $b=0; more compactly
Message-Id: <dwilga-MUNGE-FC6851.14284421012005@nap.mtholyoke.edu>

In article <Xns95E5693CBA241asu1cornelledu@132.236.56.8>,
 "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote:

> William Goedicke <goedicke@goedsole.com> wrote in 
> news:m3pszy25ih.fsf@smtp.comcast.net:
> 
> > I'm probably missing some potential gotcha' but, I've been successfully
> > using:
> > 
> > my( $a, $b, $c);
> > 
> > for years.  This is, of course, only good for initializing to null/0.
> 
> That initializes the variables to undef, not 0 or any other value.

Which is why I tend to use:

  my( $a, $b, $c ) = ( 0, 0, 0 );

This syntax also makes it fairly obvious what's going on if you want to 
use different values:

  my( $a, $b, $c ) = ( 0, 100, $_[0] );

though I obviously wouldn't recommend it for clarity if you have more 
than a few variables being assigned.

-- 
Dan Wilga          dwilga-MUNGE@mtholyoke.edu
** Remove the -MUNGE in my address to reply **


------------------------------

Date: 21 Jan 2005 11:56:17 -0800
From: binnyva@hotmail.com (Binny V A)
Subject: Sorting an Array by Another
Message-Id: <68cd8f94.0501211156.4e292eb1@posting.google.com>

Hello Everyone,

How do I sort the '@words' array to give it the value, 
"One", "Two", etc. by using the '@numbers' array? I tried
to do so in the following way - but it won't work.

my @words  = ( "Five","Ten","Seven","Two","Six","Nine","One","Eight","Three","Four"
);
my @numbers= ( "5","10","7","2","6","9","1","8","3","4" );

my $count = -1;
@words = sort { $count++; $numbers[$count] <=> $numbers[$count+1]; }
@words;
@numbers = sort { $a <=> $b } @numbers;

print "@numbers\n@words";

How do I do it?

Thanking You,
Binny V A
http://www.geocities.com/binnyva/code


------------------------------

Date: 21 Jan 2005 12:16:39 -0800
From: drleeds@gmail.com
Subject: Re: Sorting an Array by Another
Message-Id: <1106338599.822628.252590@c13g2000cwb.googlegroups.com>


Binny V A wrote:
> Hello Everyone,
>
> How do I sort the '@words' array to give it the value,
> "One", "Two", etc. by using the '@numbers' array? I tried
> to do so in the following way - but it won't work.
>
> my @words  = (
"Five","Ten","Seven","Two","Six","Nine","One","Eight","Three","Four"
> );
> my @numbers= ( "5","10","7","2","6","9","1","8","3","4" );
>
> my $count = -1;
> @words = sort { $count++; $numbers[$count] <=> $numbers[$count+1]; }
> @words;
> @numbers = sort { $a <=> $b } @numbers;
>
> print "@numbers\n@words";
>
> How do I do it?
>
> Thanking You,
> Binny V A
> http://www.geocities.com/binnyva/code


#!/usr/bin/perl

use warnings;
use strict;

my @words = (
"Five","Ten","Seven","Two","Six","Nine","One","Eight","Three","Four");
my @numbers= ( "5","10","7","2","6","9","1","8","3","4" );

my %hash_slice;
@hash_slice{@numbers} = @words;

print "$_ $hash_slice{$_}\n" for sort {int $a <=> int $b} keys
%hash_slice;



------------------------------

Date: 21 Jan 2005 20:26:26 GMT
From: xhoster@gmail.com
Subject: Re: Sorting an Array by Another
Message-Id: <20050121152626.476$8L@newsreader.com>

binnyva@hotmail.com (Binny V A) wrote:
> Hello Everyone,
>
> How do I sort the '@words' array to give it the value,
> "One", "Two", etc. by using the '@numbers' array? I tried
> to do so in the following way - but it won't work.
>
> my @words  = ( "Five","Ten","Seven","Two","Six","Nine","One","Eight",
> "Three","Four" );
> my @numbers= ( "5","10","7","2","6","9","1","8","3","4" );


my @idx = sort {$numbers[$a] <=> $numbers[$b]} 0..$#numbers;
@words=@words[@idx];


(You could inline it all and get rid of @idx, if you really wanted
to objuscate it.)

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: 21 Jan 2005 20:46:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Sorting an Array by Another
Message-Id: <csrpnk$t60$1@mamenchi.zrz.TU-Berlin.DE>

 <drleeds@gmail.com> wrote in comp.lang.perl.misc:
> 
> Binny V A wrote:
> > Hello Everyone,
> >
> > How do I sort the '@words' array to give it the value,
> > "One", "Two", etc. by using the '@numbers' array? I tried
> > to do so in the following way - but it won't work.
> >
> > my @words  = (
> "Five","Ten","Seven","Two","Six","Nine","One","Eight","Three","Four"
> > );
> > my @numbers= ( "5","10","7","2","6","9","1","8","3","4" );

[...]

The code below is basically a sound approach.  A few notes:

> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> my @words = (
> "Five","Ten","Seven","Two","Six","Nine","One","Eight","Three","Four");
> my @numbers= ( "5","10","7","2","6","9","1","8","3","4" );
> 
> my %hash_slice;

A slight misnomer.  %hash_slice is a hash, not a hash slice.  You intend
to use a slice of it, but I don't think that's not a good reason for
naming it so.

> @hash_slice{@numbers} = @words;
> 
> print "$_ $hash_slice{$_}\n" for sort {int $a <=> int $b} keys

Why the int() in the comparison?.  With the given data it's unnecessary,
and if someone decided to add "1.5" and "One and a Half", it would get
out of whack.

Using a hash slice is probably the standard solution for an indirect
sort like this, but when hash keys are small integers, as is the case
here, one can always consider using an array instead.

Anno


------------------------------

Date: 21 Jan 2005 14:10:40 -0800
From: drleeds@gmail.com
Subject: Re: Sorting an Array by Another
Message-Id: <1106345440.079335.93740@c13g2000cwb.googlegroups.com>

Thanks for corrections.  I forgot that <=> is a numerical comparison
operator that will put the arguments into a numerical context.

I was afraid of getting: 1 10 2 3 4 5 6 7 8 9 due to a comparison of
strings, but in this case, the strings are implicitly cast to numbers
for the comparison due to the nature of the <=> operator.

I'm working towards the right to Hubris, but not quite there yet :-)
drleeds@gmail.com



------------------------------

Date: 21 Jan 2005 22:12:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Whats the variable holding the dir seperator?
Message-Id: <csrunm$1sk$2@mamenchi.zrz.TU-Berlin.DE>

Leonard Challis <perl@lennychallis.co.uk> wrote in comp.lang.perl.misc:
> "A. Sinan Unur wrote
> 
> > On the other hand, if $dir1, $dir2 and $file are variables, you end up
> > with:
> >
> > my $path = $dir1.$*.$dir2.$*.$file.'.ext';
> 
> I agree it is a little bit unpretty.

If that were the only problem, it could be amended:

    my $path = join $* => $dir1, $dir2, $file;

For full qualified path names,

    my $path = join $* => '', $dir1, $dir2, $file;

would do.

But, as the rest of the thread states, "the" directory delimiter is only
a small part of making filenames portable, too small to be useful.

Also, you couldn't name the variable anything but $/, and that's taken :)

Anno


------------------------------

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 7681
***************************************


home help back first fref pref prev next nref lref last post