[11170] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4770 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 28 15:07:29 1999

Date: Thu, 28 Jan 99 12:01:31 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 28 Jan 1999     Volume: 8 Number: 4770

Today's topics:
    Re: Request for negative value list indexes (M.J.T. Guy)
    Re: Sorting a file in Perl question ::  please help :) <emschwar@mail.uccs.edu>
    Re: Sybperl - Specifying the interface file <michael_mongeau@stratus.com>
    Re: Sybperl - Specifying the interface file <"rajasingh_james@"@jpmorgan.com>
    Re: system function, Pros and Cons?? <jc@uwm-dev.gte.com>
    Re: system function, Pros and Cons?? <jc@uwm-dev.gte.com>
    Re: The behaviour of split() <mhofer@jpmorgan.com>
    Re: there must be a simpler way, can anyone suggest one <michael_mongeau@stratus.com>
    Re: unix command displayed when using PIPES with open. (Greg Ward)
    Re: unix command displayed when using PIPES with open. <neil.rutherford@cableinet.co.uk>
        URI.pm Problem <derek_price@stortek.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 28 Jan 1999 18:09:35 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Request for negative value list indexes
Message-Id: <78q94v$drd$1@pegasus.csx.cam.ac.uk>

In article <39k8y8v0tt.fsf@ibnets.com>, Uri Guttman  <uri@ibnets.com> wrote:
>>>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:
>
>  BL> 	@ary = qw(A B C D E) $first = $ary[0]; @rest = @ary[2 .. -1]; #
>  BL> does NOT work, because -1 < 2
>
>.. is defined as an incrementing operation. so how could it handle 2 .. -1?
>
>to get what you want just use reverse as in:
>
>	@ary[reverse -1 .. 2] 
>or
>	reverse @ary[-1 .. 2]
>
>so there is no need for a decrementing ..

But that doesn't do what was being asked.   He wanted @ary[2, 3, 4] but
you're giving him    @ary[2, 1, 0, 4].

AFAIK there's no painless way of doing this without $#ary.


Mike Guy


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

Date: 28 Jan 1999 11:26:54 -0700
From: "Eric The Read" <emschwar@mail.uccs.edu>
Subject: Re: Sorting a file in Perl question ::  please help :)
Message-Id: <xkfvhhrfe35.fsf@valdemar.col.hp.com>

"Steve Jackson" <steve@NOSPAMcyber-distributors.com> writes:
> There are 9 fields for each line.  I suppose I need to open the file and
> put the contents in an array - but then I'm lost when it comes to sorting
> by a field or something?  BAsically I need the whole file read and then
> sorted
> alphabetically by the second field and then put the sorted information 
> back into the seven.txt file.

perldoc perlfaq4 "How do I sort an array by (anything)?"

-=Eric


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

Date: Thu, 28 Jan 1999 12:50:48 -0500
From: "Michael Mongeau" <michael_mongeau@stratus.com>
Subject: Re: Sybperl - Specifying the interface file
Message-Id: <78q80r$rl8@transfer.stratus.com>


James Rajasingh <"rajasingh_james@"@jpmorgan.com> wrote in message
news:78q4ir$ks0$3@hardcopy.ny.jpmorgan.com...
>Hi All,
>
>I am new to perl and have got a few questions regarding use of the
>sybperl package.
>1) How do I specify the interface file to use when trying to connect to
>a SYBASE server using sybperl ?
>2) What version of sybperl do I need to accomplish 1)
>3) Is there a document somewhere which documents all the sybperl
>functions. I have a document
>is titled "Sybperl 2.0: Using the Sybase::CTlib module" but it does not
>tell me how to do 1)

1. The environment variable SYBASE is used to locate the interfaces file.
Just add this to your script:

   $ENV{'SYBASE'} = "/path/to/sybase";   (enter the correct path on your
system, or course)

The interfaces file in this directory is the one used.

2. I'm using sybperl 2.09 DBLib and it works great.

3.  The POD files are in a directory called "pod" in the installation
directory.   If you don't know what POD is try typing "perldoc perlpod".

 Michael Mongeau








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

Date: Thu, 28 Jan 1999 13:54:59 -0500
From: James Rajasingh <"rajasingh_james@"@jpmorgan.com>
Subject: Re: Sybperl - Specifying the interface file
Message-Id: <78qbo7$mvh$2@hardcopy.ny.jpmorgan.com>

Michael Mongeau wrote:

> James Rajasingh <"rajasingh_james@"@jpmorgan.com> wrote in message
> news:78q4ir$ks0$3@hardcopy.ny.jpmorgan.com...
> >Hi All,
> >
> >I am new to perl and have got a few questions regarding use of the
> >sybperl package.
> >1) How do I specify the interface file to use when trying to connect to
> >a SYBASE server using sybperl ?
> >2) What version of sybperl do I need to accomplish 1)
> >3) Is there a document somewhere which documents all the sybperl
> >functions. I have a document
> >is titled "Sybperl 2.0: Using the Sybase::CTlib module" but it does not
> >tell me how to do 1)
>
> 1. The environment variable SYBASE is used to locate the interfaces file.
> Just add this to your script:
>
>    $ENV{'SYBASE'} = "/path/to/sybase";   (enter the correct path on your
> system, or course)
>
> The interfaces file in this directory is the one used.
>
> 2. I'm using sybperl 2.09 DBLib and it works great.
>
> 3.  The POD files are in a directory called "pod" in the installation
> directory.   If you don't know what POD is try typing "perldoc perlpod".
>
>  Michael Mongeau

Thanks for the reply Micheal,
I guess I did not frame question number 1 properly. I am aware of the
interface file in $SYBASE/instal.
But I want to specify my own interface file for the connection. Something
similar to the -I option in isql/sqsh
Thanks
James







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

Date: Thu, 28 Jan 1999 14:15:06 -0500
From: John Chambers <jc@uwm-dev.gte.com>
Subject: Re: system function, Pros and Cons??
Message-Id: <36B0B73A.BD5224D@uwm-dev.gte.com>

Abigail wrote:

> Do you honestly believe that the basic UNIX tools are compatible?
> Even very old tools like 'grep' and 'awk' are different between
> well-known UNIX platforms as Solaris and HP-UX.

Bad examples there! To a perl programmer, grep and awk are obsolete,
sincer their jobs can be done more easily in perl.  Hardly any need 
to use system() to call these programs.

OTOH, I've often found myself writing perl scripts that fire up
"make" as a subprocess.  That's definitely not easier in perl.
And, of course, it's about as non-portable as you can get. It
doesn't even port to the next directory.  (Hmm ... Maybe we need
a campaign to eliminate all those Makefiles, on the grounds that
they are scripts that are not very portable. ;-)

Now I suppose someone will give me an example where it's better
to fire up a grep subprocess than to do it in perl.  I wonder if
there are such examples?

(I suppose you could have an old awk script that seems to work,
so it's easier to code system("awk ...") than to do it in perl,
but that's really a stretch.  Even in that case, I try to find
time to run it thru a2p and be done with it.)


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

Date: Thu, 28 Jan 1999 14:25:06 -0500
From: John Chambers <jc@uwm-dev.gte.com>
Subject: Re: system function, Pros and Cons??
Message-Id: <36B0B992.1F8FBCCC@uwm-dev.gte.com>

Abraham Grief wrote:
> 
> Overall,  I would say that system() can save you time and can
> prevent the rewriting of programs that already exist, but I still
> think it should be generally avoided for reasons of portability,
> reusability, and performance.

And I'd say that's a pretty good summary of the major arguments
both for and against using system().  Perl is used for a lot of
quick-and-dirty, one- (or few-)time jobs, and for them, system()
can materially shorten the time it takes to make it work.  Perl 
is also used for a lot of heavy-duty programs, especially CGI 
scripts that are run a lot, and for them, you should probably 
be very wary of using system() or `` or open() on a pipe, and 
try to do as much as possible in the perl code.  

It's likely that the "don't use system()" attitute comes from
people thinking they're writing a quick-and-dirty one-timer,
then discovering that it's turned into a tool that everyone
in the place is using.  How often has that happened to you?
Embarassing, isn't it?


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

Date: Thu, 28 Jan 1999 13:14:42 -0500
From: "Michael D. Hofer" <mhofer@jpmorgan.com>
Subject: Re: The behaviour of split()
Message-Id: <36B0A912.1D18@jpmorgan.com>

Tom Briles wrote:
> 
> Michael wrote:
> 
> > Hello!
> >
> > I have encountered difference in behaviour of the split function that
> > I do not understand:
> >
> > In two different scripts I have strings like:
> > "0.01  -5.24  ...."
> >
> > Those I split into an array using split(/\s+/, $string )
> >
> > In one script the first element is found in the array, and in the other
> > it is not.
> > Any explanation?
> >
> > Michael
> 
> And the answer is...
> 
> One script has it coded one way, the other script has it coded another way!
> 
> (I.e., post the code, and maybe we can help.)
> 
> - Tom

Nah, Nah, Nah!  Let's do it blind!  I'll bet he has a leading blank
space in the string in the second instance:  The first element of the
array will then be "".

Can you guess how many times _I've_ done that?

-- 
Michael D. Hofer
Internet Services
212 235 4415


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

Date: Thu, 28 Jan 1999 13:00:24 -0500
From: "Michael Mongeau" <michael_mongeau@stratus.com>
Subject: Re: there must be a simpler way, can anyone suggest one?
Message-Id: <78q8ir$rvn@transfer.stratus.com>


23_skidoo <23_skidoo@geocities.com> wrote in message
news:36B09D25.1995@geocities.com...

>as these items will not necessarily be added to the data file in the
>order they need to be displayed, i need to sort the file by date order
>so to separate the date from the headline i've done the following:
>
>$string = "valentines day <!--19990214-->\n";
>#$string used for practive purposes. headline could be anything
>
>@string_split = split(/<!--/, $string);
>
>$date = $string_split[1];
>
>$date =~ s/-->\n//;
>
>does anyone have any suggestions on how to neaten that up a bit? it
>seems a bit clunky.

How about this:

 ($date) = $string =~ /<!--(\d+)-->/;

It does a regex search of $string for one or more digits between the HTML
comments, and the surrounding parentheses cause the string that matches to
be assigned to $date.

Michael Mongeau






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

Date: 28 Jan 1999 18:25:28 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: unix command displayed when using PIPES with open.
Message-Id: <78qa2o$7i5$1@news0-alterdial.uu.net>

neil_rutherford@yahoo.com <neil_rutherford@yahoo.com> wrote:
> When i execute the following source code, the command being executed
> by the pipe is being displayed on the screen... how do i stop
> this from happening.... without re-directing it..... not even to bit-heaven
> (/dev/null).... if it's done in C, it doesn't happen.

Ummm... did you even read your code?  There's a 'print "$syscmd\n"' in
there, you know.

> #!/usr/bin/perl -w
> use strict;
> use 5.004;
> 
> my( $syscmd ) = "prs -e -d\":M: :I: :D: by :P:\" $ENV{'PROJECTDIR'}/SCCS/";
> my( @sccslist ) = ();
> my( $line );
> 
> print "$syscmd\n";
  ^^^^^

Right here.  Now, why on *earth* would that statement print the value of
$syscmd followed by a newline?  It just doesn't make sense... >smirk<

> open( FILEPIPE, "$syscmd|" ) or die "Unable To Open Pipe\n";
> @sccslist = <FILEPIPE>;
> close( FILEPIPE );

BTW it's a good idea to check $? after closing a pipe -- it's only after
closing that you find out if the program being spawned wasn't found or
wasn't executable (or something).  'open' failure usually means
"couldn't fork" (which you would be able to find out if you had included
$! in your 'die' after 'open' above).

        Greg
-- 
Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                      voice: +1-703-620-8990 x287
Reston, Virginia, USA  20191-5434               fax: +1-703-620-0913


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

Date: Thu, 28 Jan 1999 19:18:12 -0000
From: "Neil Rutherford" <neil.rutherford@cableinet.co.uk>
Subject: Re: unix command displayed when using PIPES with open.
Message-Id: <78qdbd$pmk$1@news1.cableinet.co.uk>

HAHA....  what a day I've had......... sorry Greg.... this must go down as
the
stupidest thing in my professional career....

It's one of those days where you need a second set of eyes to look at your
mistakes........   I was working on something at work when I should have
been
working on other things.... I kept switching between what I was meant to
have been
working on... and getting a little pissed at why it would work.........

I was to busy looking at the open() onwards..... well that's my lame excuse.

Is there any cure for code blindness?  If not... I'm finished.

Now I look as stupid as I've been feeling for a while.

Thanks Greg!


Greg Ward wrote in message <78qa2o$7i5$1@news0-alterdial.uu.net>...
>neil_rutherford@yahoo.com <neil_rutherford@yahoo.com> wrote:
>> When i execute the following source code, the command being executed
>> by the pipe is being displayed on the screen... how do i stop
>> this from happening.... without re-directing it..... not even to
bit-heaven
>> (/dev/null).... if it's done in C, it doesn't happen.
>
>Ummm... did you even read your code?  There's a 'print "$syscmd\n"' in
>there, you know.
>
>> #!/usr/bin/perl -w
>> use strict;
>> use 5.004;
>>
>> my( $syscmd ) = "prs -e -d\":M: :I: :D: by :P:\"
$ENV{'PROJECTDIR'}/SCCS/";
>> my( @sccslist ) = ();
>> my( $line );
>>
>> print "$syscmd\n";
>  ^^^^^
>
>Right here.  Now, why on *earth* would that statement print the value of
>$syscmd followed by a newline?  It just doesn't make sense... >smirk<
>
>> open( FILEPIPE, "$syscmd|" ) or die "Unable To Open Pipe\n";
>> @sccslist = <FILEPIPE>;
>> close( FILEPIPE );
>
>BTW it's a good idea to check $? after closing a pipe -- it's only after
>closing that you find out if the program being spawned wasn't found or
>wasn't executable (or something).  'open' failure usually means
>"couldn't fork" (which you would be able to find out if you had included
>$! in your 'die' after 'open' above).
>
>        Greg
>--
>Greg Ward - software developer                    gward@cnri.reston.va.us
>Corporation for National Research Initiatives
>1895 Preston White Drive                      voice: +1-703-620-8990 x287
>Reston, Virginia, USA  20191-5434               fax: +1-703-620-0913








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

Date: Thu, 28 Jan 1999 10:04:16 -0700
From: "Derek R. Price" <derek_price@stortek.com>
Subject: URI.pm Problem
Message-Id: <36B0988F.C55FD3BE@stortek.com>

I'm at a loss.  I was attempting to install the URI package using CPAN
and got the following error:

------- Begin Inclusion -------

Running make for GAAS/URI-1.00.tar.gz
Unwrapped into directory /home/pricedr/.cpan/build/URI-1.00
Has already been processed within this session
Running make test
PERL_DL_NONLAZY=1 /build/nss/tools/test/sparc-SunOS-5.5/bin/perl
-Iblib/arch -Iblib/lib
-I/build/nss/tools/test/sparc-SunOS-5.6/perl/lib/sun4-solaris
-I/build/nss/tools/test/sparc-SunOS-5.6/perl/lib -e use Test::Harness
qw(&runtests $verbose); $verbose=0; runtests @ARGV; t/*.t
t/abs...............ok t/data..............Cant locate object method
media_type via package URI::_foreign at t/data.t line 9.  dubious
Test returned status 2 (wstat 512, 0x200)
DIED. FAILED tests 2-21
Failed 20/21 tests, 4.76% okay
t/file..............ok
t/generic...........ok
t/heuristic.........ok
t/http..............ok
t/mailto............ok
t/mix...............ok
t/news..............ok
t/old-absconf.......ok
t/old-base..........ok
t/old-relbase.......ok
t/pop...............ok
t/roy-test..........ok
Failed Test  Status Wstat Total Fail  Failed  List of failed
t/data.t          2   512    21   20  95.24%  2-21
Failed 1/14 test scripts, 92.86% okay. 20/295 subtests failed, 93.22%
okay.
make: *** [test_dynamic] Error 29
/apps/bin/make testNOT OK
Running make install
make test had returned bad status, wont install without force

------- End Inclusion -------

Derek





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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4770
**************************************

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