[25216] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7461 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 29 14:06:10 2004

Date: Mon, 29 Nov 2004 11:05:07 -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           Mon, 29 Nov 2004     Volume: 10 Number: 7461

Today's topics:
    Re: $SIG{IO} example <gifford@umich.edu>
    Re: 500 Can't connect to search.cpan.org:80 (Bad protoc <bik.mido@tiscalinet.it>
    Re: 500 Can't connect to search.cpan.org:80 (Bad protoc <bik.mido@tiscalinet.it>
    Re: export to excel <jwillmore@fastmail.us>
    Re: export to excel <jwillmore@fastmail.us>
        FAQ 4.12: How do I find the day or week of the year? <comdog@panix.com>
    Re: hex to binary conversion (Mark Jason Dominus)
    Re: Matt's formail not working outside domain <1usa@llenroc.ude.invalid>
        Minimize black screen <jimsimpson@cox.net>
    Re: Minimize black screen <jwillmore@fastmail.us>
    Re: Need some problemsolving-cgi/xml <jwillmore@fastmail.us>
        Perl Executable and Script Name -- NOT Args (Walt Stoneburner)
    Re: Perl Executable and Script Name -- NOT Args <digital-x@comcast.net>
    Re: Perl Executable and Script Name -- NOT Args <mritty@gmail.com>
    Re: perl trim function <uri@stemsystems.com>
    Re: Sorting <wksmith@optonline.net>
    Re: Unix commands and perl (AS)
    Re: Unix commands and perl <jwillmore@fastmail.us>
    Re: Unix commands and perl xhoster@gmail.com
    Re: Using files to transfer data between processes <gifford@umich.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 29 Nov 2004 11:54:59 -0500
From: Scott W Gifford <gifford@umich.edu>
Subject: Re: $SIG{IO} example
Message-Id: <qsz7jo4ppcs.fsf@rygar.gpcc.itd.umich.edu>

Sébastien Cottalorda <sppNOSPAM@monaco377.com> writes:

[...]

> I've made that but it doesn't seem to work.
> Do you have a SIG{IO} exemple program

You have to set the file descriptor to asynchronous to get SIGIO when
data becomes available.  See the O_ASYNC flag in fcntl(2) and open(2).

IIRC, Stevens talks about this technique in Advanced Programming in
the Unix Environment, so you can find sample code in C there.

According to the manpages, this is specific to BSD-derived systems and
Linux.

----ScottG.


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

Date: Mon, 29 Nov 2004 16:08:29 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: 500 Can't connect to search.cpan.org:80 (Bad protocol 'tcp') at web.plline 24.
Message-Id: <abemq0956md8ms7lm0k22kgio893105f59@4ax.com>

On Mon, 29 Nov 2004 12:21:19 +0100, Michele Dondi
<bik.mido@tiscalinet.it> wrote:

>do with any shell (apart a possible ambiguity with C<cd>, that could
>be interpreted as an internal Perl command or a shell one).

Incidentally this *is* BS!


Sorry,
Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Mon, 29 Nov 2004 16:08:31 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: 500 Can't connect to search.cpan.org:80 (Bad protocol 'tcp') at web.plline 24.
Message-Id: <tpemq0d3u8g8d4vdpsloivf8avbmq7hgja@4ax.com>

On Mon, 29 Nov 2004 12:02:54 GMT, "Peter Wyzl" <wyzelli@yahoo.com>
wrote:

>To get back to the original comment, Bob said that as far as he knew it had 
>to have a literal backslash if Windows was looking at it.  I countered that 
>this is not true.  There are cases where Windows requires a literal 

Let me see... he wrote:

| Not sure why, but removing the bogus environment variable setting makes 
| it work on my system.  Somewhere in the bowels of LWP, it must refer to 
| some Windoze component that needs a valid setting for the SYSTEMROOT 
| environment variable.  I'm not sure why you'd want to mess with that one 
| anyway -- but I'm pretty sure it will have to have genuine backslashes 
| in it if Windoze is looking at it.

It *seems* to me that he's saying that *in this particular case*
"genuine backslashes" may be required. Also he has not claimed
anything for certain, and it seems to me that he has stressed enough
that he's making a guess, even if he's pretty (note: *not*
absoultely!) sure about it.

In other words it seems to me that he's never claimed that genuine
backslashes are required in Windows paths. But to be fair I admit that
his sentence could be interpreted in both ways so I'm not arguing
about your interpretation, notwithstanding the fact that it's not the
same as mine.

However in your answer you included these lines:

: command.com and cmd.exe both understand / as well as \ for directory 
: seperators.

(incidentally I can't understand why you mentioned them, since they
have few to nothing to do with what we/you were talking about...)

to which bob replied in turn:

| Bull****.  A / does not work as a directory separator in DOS or Windoze, 
| and never has -- it is a command options or "switch" designator:
[snip examples]

Again his statement is ambiguous for "DOS or Windoze" may refer both
to the system (or some component of it) or to the shell. Both the fact
that he was aswering to your lines quoted above (which are the *only
ones* of your post he quoted) and the examples he gave can make one
undoubtedly sure he's referring to the latter.

Then again you replied

: I beg to differ... the problem you have is with the dir command, not 
: cmd.exe.
: 
: you can 'cd' to /junk
: 
: you can cd to /junk/junk2 etc

In cmd.exe that is, I didn't know that, but I'll take your word for
it. In command.com not for sure:

  C:\WINDOWS>cd /temp
  Opzione non valida - /TEMP
  
  C:\WINDOWS>cd "/temp"
  Opzione non valida - /TEMP"
  
  C:\WINDOWS>cd "C:/temp"
  
  C:\WINDOWS>

: open (IN, 'c:/junk/junk2/file.txt') or die "Can't $!\n";

This is perl code and has nothing to do with cmd.exe or command.com,
just as much the latter ones had nothing to do with the subject matter
being discussed in the first place.

>backslash (File::Find suffers from it) but it is not universally true.  Bob 
>gave an example where a forward slash is not accepted (/ being a switch 
>delimiter) and I gave an example where it is.  Within Perl / is accepted 

Again, I must admit that I didn't know cmd.exe does that. I would say
that it is of little use anyway, since (most) external commands won't
understand it in any case, so that it may generate some confusion IMHO
to mix the two separators on the cmd line.

>because perl does the right thing.  Stating that 'Windows requires a literal 
>backslash' is what was incorrect.

Yes, it is incorrect. But as I wrote above, it doesn't seem to me that
Bob ever claimed that.

OTOH I thought that what you said of cmd.exe and command.com was
wrong: now it may well be that at least as far as cmd.exe is concerned
it is *not* strictly wrong.

>However, this was not intended to be a discussion about Windows or cmd.exe. 
>It WAS intended to be a discussion about what happens within [Pp]erl and 
>that / can be used as much as \\ in programs written in Perl.  This enhances 
>readability and portability.

I agree. I have never said the opposite. FWIW I also always use '/'.

>(trying to make?) is that / works in perl.  Why you have to tell me I wrote 
>BS and then state the same thing is a little confusing to me.

Both my cmt and Bob's original one were referring exclusively to your
claim about Windows' shells.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Mon, 29 Nov 2004 11:57:27 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: export to excel
Message-Id: <pan.2004.11.29.16.57.26.40426@fastmail.us>

On Sun, 28 Nov 2004 13:57:00 +0000, Leon wrote:

> "ocap" <ocap8891@yahoo.it> wrote in message
> news:c4495e9e.0411280102.3e882960@posting.google.com...
>> I would like write to Excel file the result of a query on a db table
>> with a CGI Perl. My CGI allows output to HTML table by Template.pm
>> module; can you help me?
>> With Java it's very easy
>>
>>       response.setContentType("application/vnd.ms-excel")
>>
>> But with Perl? In the same script I want allow output in html and
>> output in excel file (user choices). Can I do it using Template.pm
>> module?
>>
>> Hi
>> ocap
> Not sure about the Template.pm as I haven't used it, but you could just
> write the results from your query out to a .csv file.  This would be Excel
> friendly and very easy to import.

Or, in Perl, you could just send the proper header ....

#"quick and dirty" in the main script using the template
print "Content-type: application/vnd.ms-excel\n\n";

#using the CGI module in the main script using the template
print header(-type => 'application/vnd.ms-excel');
#-or-
print $query->header(-type => 'application/vnd.ms-excel');

HTH

Jim



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

Date: Mon, 29 Nov 2004 11:57:52 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: export to excel
Message-Id: <pan.2004.11.29.16.57.52.291803@fastmail.us>

On Sun, 28 Nov 2004 01:02:54 -0800, ocap wrote:

> I would like write to Excel file the result of a query on a db table
> with a CGI Perl. My CGI allows output to HTML table by Template.pm
> module; can you help me?
> With Java it's very easy
> 
>       response.setContentType("application/vnd.ms-excel")
> 
> But with Perl? In the same script I want allow output in html and
> output in excel file (user choices). Can I do it using Template.pm
> module?


Or, in Perl, you could just send the proper header ....

#"quick and dirty" in the main script using the template
print "Content-type: application/vnd.ms-excel\n\n";

#using the CGI module in the main script using the template
print header(-type => 'application/vnd.ms-excel');
#-or-
print $query->header(-type => 'application/vnd.ms-excel');

HTH

Jim



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

Date: Mon, 29 Nov 2004 17:03:02 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 4.12: How do I find the day or week of the year?
Message-Id: <cofko6$o8j$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

4.12: How do I find the day or week of the year?

    The localtime function returns the day of the week. Without an argument
    localtime uses the current time.

        $day_of_year = (localtime)[7];

    The POSIX module can also format a date as the day of the year or week
    of the year.

            use POSIX qw/strftime/;
            my $day_of_year  = strftime "%j", localtime;
            my $week_of_year = strftime "%W", localtime;

    To get the day of year for any date, use the Time::Local module to get a
    time in epoch seconds for the argument to localtime.

            use POSIX qw/strftime/;
            use Time::Local;
            my $week_of_year = strftime "%W", 
                    localtime( timelocal( 0, 0, 0, 18, 11, 1987 ) );

    The Date::Calc module provides two functions for to calculate these.

            use Date::Calc;
            my $day_of_year  = Day_of_Year(  1987, 12, 18 );
            my $week_of_year = Week_of_Year( 1987, 12, 18 );



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Mon, 29 Nov 2004 18:39:22 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: hex to binary conversion
Message-Id: <cofqcq$p73$1@plover.com>

In article <41aa7ee2$1@news.iconz.co.nz>,
Jeffrey Ross <jeffrey.rossATairways.co.nz@no.spam> wrote:
>How do I do it for lines of arbitrary length?

Here's a non-scary perl way:

        %h2b = (0 => "0000", 1 => "0001", 2 => "0010", 3 => "0011",
                4 => "0100", 5 => "0101", 6 => "0110", 7 => "0111",
                8 => "1000", 9 => "1001", a => "1010", b => "1011",
                c => "1100", d => "1101", e => "1110", f => "1111",
                );

        $hex = "414243";
        ($binary = $hex) =~ s/(.)/$h2b{lc $1}/g;
        print $binary, "\n";

Hope this helps.


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

Date: 29 Nov 2004 17:27:52 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Matt's formail not working outside domain
Message-Id: <Xns95B07ECB3C7A2asu1cornelledu@132.236.56.8>

"Peter Wyzl" <wyzelli@yahoo.com> wrote in news:Z2dqd.50912$K7.19021@news-
server.bigpond.net.au:

> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message 
> news:Xns95AEB1B72D74Casu1cornelledu@132.236.56.8...
>: mortgageloan2004@aol.com (Mortgageloan2004) wrote in
>: news:20041127143648.21945.00001339@mb-m06.aol.com:
>:
>: > I have READ all his documentation carefully.
>:
>: No one cares.
>:
>: > Why isn't this working?
>:
>: Your problem, not ours.
> 
> True.  You seem to have an entirely different problem.

It has to do with lazy people not even bothering to use Google before 
dumping stuff in to this group.

http://www.google.com/search?q=matt's+formmail

yields a bunch of links.

Follow the first one. On that page, click on the link about setting up 
formmail. It will take you to:

http://www.scriptarchive.com/readme/formmail.html#setting_up

And read the bit about @referers:

	@referers = ('scriptarchive.com','YOUR_IP');
 	This array allows you to define the domains on which you allow forms 
to reside and use this installation of FormMail. 

etc so on and so forth.

Of course, if the OP had actually read the documentation rather than 
claiming to have done so, he/she would also have noticed the bit about nms 
formmail etc.

So, in a nutshell, that's my problem. I will nurture and cherish it.

Sinan.


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

Date: Mon, 29 Nov 2004 10:56:42 -0500
From: "jim simpson" <jimsimpson@cox.net>
Subject: Minimize black screen
Message-Id: <sFHqd.4076$QR.3735@lakeread01>

Is there anyway to minimize the black screen while a Perl script is running
an then return it to normal just before the script comcludes?

Thanks,

Jim




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

Date: Mon, 29 Nov 2004 11:45:30 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: Minimize black screen
Message-Id: <pan.2004.11.29.16.45.28.985284@fastmail.us>

On Mon, 29 Nov 2004 10:56:42 -0500, jim simpson wrote:

> Is there anyway to minimize the black screen while a Perl script is running
> an then return it to normal just before the script comcludes?
> 
> Thanks,
> 
> Jim

Here are a few TinyURL's of a Google Groups search for your question:

http://tinyurl.com/6pokb
http://tinyurl.com/6v755
http://tinyurl.com/6ebg7

If you have further questions, you might want to post to comp.lang.perl.tk
 ... since that is the perl/Tk specific newsgroup :-)

HTH

Jim


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

Date: Mon, 29 Nov 2004 11:23:25 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: Need some problemsolving-cgi/xml
Message-Id: <pan.2004.11.29.16.23.23.397948@fastmail.us>

On Mon, 29 Nov 2004 07:22:05 +0100, lievemario wrote:

> I have written the following perl program,

<snip>

This, IMHO, is the most important part of the post I posted to this
question before.

(last portion of <pan.2004.11.25.19.30.18.981436@fastmail.us>)

You should really read the documentation for the various modules you're
using.  It looks like you cobbled together something from various sources
and, well, this ain't going to work the way you expect it to.  Try small
parts of what you're trying to do (for example, do some small XML
transformations [at the command line] first and small do nothing CGI
scripts). Test them and see that they work the way you expect them to.
Then put it all together for the final product.

HTH

Jim


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

Date: 29 Nov 2004 08:02:59 -0800
From: wls@wwco.com (Walt Stoneburner)
Subject: Perl Executable and Script Name -- NOT Args
Message-Id: <c1fca1a1.0411290802.58a8719f@posting.google.com>

I'm stumbling trying to find out if this is even possible with Perl. 
Anyone know?

In a C program, it's possible to get the executable's name as argv[0]
-- a trick that's useful when you want one executable and a bunch of
symbolic links, but the program's behavior to change based on what it
was called.  You'll note some crypto packages do this, as it is
simplier to have multiple man pages.

Since the Perl engine is the executable in reality, I figure the best
I'd get is the fully qualified path name of the running executable --
which might be useful if I have more than one version of Perl
installed.

Additionally, if I wanted a program to know about it's own source
file, it might be interesting to see what was passed to Perl.  This is
_different_ than command line arguments being passed to a Perl script.
 I'd like to know if the Perl engine itself exposes what was passed to
it.

Anyone know if there are some magic globals or environment variables
which contain either of these two pieces of information?

-Walt Stoneburner, wls@wwco.com


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

Date: Mon, 29 Nov 2004 10:26:08 +0000
From: Kevin Mooney <digital-x@comcast.net>
Subject: Re: Perl Executable and Script Name -- NOT Args
Message-Id: <v4ednfUtgYMW0DbcRVn-vw@comcast.com>

Walt Stoneburner wrote:
> I'm stumbling trying to find out if this is even possible with Perl. 
> Anyone know?
> 
> In a C program, it's possible to get the executable's name as argv[0]
> -- a trick that's useful when you want one executable and a bunch of
> symbolic links, but the program's behavior to change based on what it
> was called.  You'll note some crypto packages do this, as it is
> simplier to have multiple man pages.
> 
> Since the Perl engine is the executable in reality, I figure the best
> I'd get is the fully qualified path name of the running executable --
> which might be useful if I have more than one version of Perl
> installed.
> 
> Additionally, if I wanted a program to know about it's own source
> file, it might be interesting to see what was passed to Perl.  This is
> _different_ than command line arguments being passed to a Perl script.
>  I'd like to know if the Perl engine itself exposes what was passed to
> it.
> 
> Anyone know if there are some magic globals or environment variables
> which contain either of these two pieces of information?
> 
> -Walt Stoneburner, wls@wwco.com

For your first question, I believe $0 is what you are looking for. 
Unfortunately I have no idea as far as your second question goes.


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

Date: Mon, 29 Nov 2004 17:23:29 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Perl Executable and Script Name -- NOT Args
Message-Id: <lWIqd.1755$nq6.1017@trndny09>

"Walt Stoneburner" <wls@wwco.com> wrote in message
news:c1fca1a1.0411290802.58a8719f@posting.google.com...
> In a C program, it's possible to get the executable's name as argv[0]
> -- a trick that's useful when you want one executable and a bunch of
> symbolic links, but the program's behavior to change based on what it
> was called.  You'll note some crypto packages do this, as it is
> simplier to have multiple man pages.
>
> Since the Perl engine is the executable in reality, I figure the best
> I'd get is the fully qualified path name of the running executable --
> which might be useful if I have more than one version of Perl
> installed.

The currently running executable is stored in $^X.  perldoc perlvar
warns you that depending on your OS, this may be a relative or absolute
path.

> Additionally, if I wanted a program to know about it's own source
> file, it might be interesting to see what was passed to Perl.  This is
> _different_ than command line arguments being passed to a Perl script.
>  I'd like to know if the Perl engine itself exposes what was passed to
> it.

The currently executing perl script is stored in $0

> Anyone know if there are some magic globals or environment variables
> which contain either of these two pieces of information?

perldoc perlvar  is the place to go to find a list of all global Perl
variables.

Paul Lalli



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

Date: Mon, 29 Nov 2004 16:12:05 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: perl trim function
Message-Id: <x7sm6sfxd8.fsf@mail.sysarch.com>

>>>>> "AJ" == Arndt Jonasson <do-not-use@invalid.net> writes:

  AJ> "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de> writes:
  >> sub trim ($) {
  >> if (! defined wantarray) {
  >> $_[0] =~ s/^\s+//;
  >> $_[0] =~ s/\s+$//;
  >> return;
  >> }
  >> my $string = shift;
  >> $string =~ s/^\s+//;
  >> $string =~ s/\s+$//;
  >> return $string;
  >> }

  AJ> sub trim1 ($) {
  AJ>     my $r = shift;
  AJ>     $$r =~ s/^\s+//;
  AJ>     $$r =~ s/\s+$//;
  AJ> }

why pass in a ref when @_ is aliased to the args? you save a deref (if
you are looking for speed).

  AJ> sub trim ($) {
  AJ>     if (! defined wantarray) {
  AJ> 	trim1 \$_[0];
  AJ> 	return;
  AJ>     }

eww, prototypes! steer clear of them in general.

  AJ>     my $string = shift;
  AJ>     trim1 \$string;
  AJ>     return $string;
  AJ> }

with a cleaner api you can easily fold that code and not need a helper
sub. something like (untested):

	sub trim {

		my $str_ref = defined wantarray ? \"$_[0]" : \$_[0] ;

		$$str_ref =~ s/^\s+// ;
		$$str_ref =~ s/\s+$// ;

		return $$str_ref if defined wantarray ;
		return ;
	}

there could be a better way to get a ref to a copy of $_[0] but that
should work ok.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Mon, 29 Nov 2004 12:09:52 -0500
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Sorting
Message-Id: <WIIqd.11351$yT7.2938@fe12.lga>


"Mahesh" <palemmahesh@yahoo.co.in> wrote in message
news:cf3354e2.0411282143.6157e6a4@posting.google.com...
> I had a two dimensional array.
>
> Suppose it is a student array where student[0] represents the student
> name and student[1] represents the date-of-birth of student.
>
> I want to sort the student array based on student[0] column so that
> the association between the name and dateofbirth remains same...
>
> Is there any way that I can sort a multi dimensional array based on
> some column.

Strictly speaking, perl does not support multi-dimensional arrays.  The
optional syntax for indexes largely frees us from this constraint.  In
perl, the structure that you describe is implemented as an array of
references, each of which refers to a two element anonymous array which
contains a student name and corresponding birthday.  Sorting is one of
the situations where the special syntax does not help much.

In terms of the implementation, you want to sort the array of
references.  The data arrays should not be changed at all.  Sherm
already provided the code to do this.

I hope this insight helps you understand the references he provided.

Bill





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

Date: 29 Nov 2004 08:47:50 -0800
From: solanki1961@yahoo.com (AS)
Subject: Re: Unix commands and perl
Message-Id: <5d085a51.0411290847.5e39c681@posting.google.com>

Thanks Xho, Villy, Christopher for your constructive suggestions. 

Sorry, everyone got distracted by my EXAMPLE. That is just one of my
set of commands that I wanted to use.  It works fine from the Unix
command line and I tried to use it within Perl to try to understand
how Perl works. I wanted to understand using something that I
understood already. I will be probably using this in several different
ways until I understand fully how to use all the various parts of
Perl.

My point is -- what do I need to do to run multiple commands taking
the output from one command into another?  I am comparatively new to
Perl and am just getting back into programming.  Michele, I would
appreciate it if you would add "how to do it" rather than just telling
me it can be done in Perl better.  In this example if someone explains
to me what to do to make it work, I will be very thankful.

BTW, you guessed right, I did not know about q// quoting till after I
saw your response and searched for it.  Thanks for a constructive
suggestion.


Michele Dondi <bik.mido@tiscalinet.it> wrote in message news:<qc1mq0d0n8077janilt46q9k1pg24alb9e@4ax.com>...
> On 28 Nov 2004 14:45:58 -0800, solanki1961@yahoo.com (AS) wrote:
> 
> >I need to take the output of one command put it into the next one use
> >that ooutput in a third command. e.g.,
> >system ('id | awk '{print $2}' |  cut -d\( -f2 | cut -d\) -f1');
> 
> Incidentally it's very very poor programming to use clumsy constructs
> calling external programs to do something that perl can do more
> reliably, clearly and fast in the first place.
> 
> In other words, no need and (no gain!) to use perl like shell
> scripting: use shell scripting if you really want that...
> 
> 
> Michele


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

Date: Mon, 29 Nov 2004 12:37:19 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: Unix commands and perl
Message-Id: <pan.2004.11.29.17.37.19.16884@fastmail.us>

On Sun, 28 Nov 2004 14:45:58 -0800, AS wrote:

> Hi,
> 
> I tried to run a set of Unix commands (separated by |) using the
> 'system' command from a perl script, but only a single command works. 
> What is a good way to do this?
> 
> I need to take the output of one command put it into the next one use
> that ooutput in a third command. e.g.,
> system ('id | awk '{print $2}' |  cut -d\( -f2 | cut -d\) -f1');
> 
> This command in itself gives me the current user's set primary group
> in Unix (Solaris)

To get the same infomation in a Perl one-liner (note: in Linux, I have my
own group for my UID; it's not really a wise thing in a production
environment):

[jim@localhost jim]$ perl -e 'print [getgrgid($<)]->[0],"\n";'
jim
[jim@localhost jim]$ 

Type `perldoc User::pwent` or `perldoc User::grent` or `perldoc perlvar`
at the command line to get documentation explaining what I did.

HTH

Jim


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

Date: 29 Nov 2004 17:40:25 GMT
From: xhoster@gmail.com
Subject: Re: Unix commands and perl
Message-Id: <20041129124025.727$Ar@newsreader.com>

solanki1961@yahoo.com (AS) wrote:
> Thanks Xho, Villy, Christopher for your constructive suggestions.
>
> Sorry, everyone got distracted by my EXAMPLE. That is just one of my
> set of commands that I wanted to use.  It works fine from the Unix
> command line and I tried to use it within Perl to try to understand
> how Perl works. I wanted to understand using something that I
> understood already.

Ah, well then.  Calling system (or using backticks) can be particularly
troublesome when you need to consider shell escaping and shell
interpolation and shell quoting and Perl escaping and Perl interpolation
and Perl quoting all together in one messy mess.  My second rule of thumb
is when in doubt, temporarily change the "system" to a "print", and make
sure that what is getting printed matches what you think the shell is
supposed to be seeing.  (Does not apply to the multi-argument form of
"system", or course)


Xho

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


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

Date: Mon, 29 Nov 2004 11:41:30 -0500
From: Scott W Gifford <gifford@umich.edu>
Subject: Re: Using files to transfer data between processes
Message-Id: <qszbrdgppz9.fsf@rygar.gpcc.itd.umich.edu>

lada77@yahoo.com (Larry) writes:

[...]

> The problem with this code is that the FIFO file handle keeps firing
> because of the end of file, i can clear it but it constantly fires off
> if there is no data to process.  I realize that I can force a wait by
> doing something like :

AFAIK, there's no way to tell select "only return if the file has
grown".  Essentially what you're doing is emulating "tail -f", which
leads to this FAQ:

    http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q5.22.html

The solution employed there, and the one I've used in similar
situations, is to simply sleep() after reaching EOF, then check after
that to see if the file has grown.  Essentially you're polling, but
since you know how the programs work, you can time the sleep()s so
that you usually don't poll unless there's data waiting.

You could also use something like tee(1) to send the data from A to B
using a pipe, but record the results as they're sent, since pipes have
the behavior you want.  Or just have A record the data in a file as
it's sent to a pipe or socket, or have B record the data as it reads
it.

-----ScottG.


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

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


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