[8653] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2271 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 7 20:07:28 1998

Date: Tue, 7 Apr 98 17:01:38 -0700
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, 7 Apr 1998     Volume: 8 Number: 2271

Today's topics:
        Simple Unix Question,  ( Simple for you maybe ) (UNIXstuff)
    Re: Simple Unix Question,  ( Simple for you maybe ) (Brian Wheeler)
    Re: Simple Unix Question,  ( Simple for you maybe ) smitty77@pacbell.net
    Re: Simple Unix Question,  ( Simple for you maybe ) (Tad McClellan)
    Re: Socket problems! (Jonathan Stowe)
    Re: Sorting in multi-line records. <ludlow@us.ibm.com>
        Sorting problem <olm@mail1.csun.edu>
    Re: Sorting problem <lr@hpl.hp.com>
    Re: Sorting problem <matt@whiterabbit.co.uk>
    Re: Subscribing to a list without duplicates <Rosie@dozyrosy.demon.co.uk>
        Trying to Match two lists <falkenl@hotmail.com>
    Re: Variable interpolation problems <rootbeer@teleport.com>
    Re: Web spider/crawler script (Jonathan Stowe)
    Re: Win::ODBC, Using "GROUP BY" SQL to output (Jonathan Stowe)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 7 Apr 1998 21:47:40 GMT
From: unixstuff@aol.com (UNIXstuff)
Subject: Simple Unix Question,  ( Simple for you maybe )
Message-Id: <1998040721474001.RAA25368@ladder01.news.aol.com>


>From with a perl script.
I want to run the UNIX command ls -l
and have the info/string stored in a variable.

If I do
$MY_VARIABLE = system (ls -l);

$MY_VARIABLE is set to equal 0, which
is the unix return code for ls.

How do I get $MY_VARIABLE to eqaul
-rwxr-xr-x  1  root   sys   ..........   some_file_name

Thanks


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

Date: 7 Apr 1998 21:59:26 GMT
From: bdwheele@indiana.edu (Brian Wheeler)
Subject: Re: Simple Unix Question,  ( Simple for you maybe )
Message-Id: <6ge7ju$rv7$1@flotsam.uits.indiana.edu>

In article <1998040721474001.RAA25368@ladder01.news.aol.com>,
	unixstuff@aol.com (UNIXstuff) writes:
> 
> From with a perl script.
> I want to run the UNIX command ls -l
> and have the info/string stored in a variable.
> 
> If I do
> $MY_VARIABLE = system (ls -l);
> 
> $MY_VARIABLE is set to equal 0, which
> is the unix return code for ls.
> 
> How do I get $MY_VARIABLE to eqaul
> -rwxr-xr-x  1  root   sys   ..........   some_file_name
> 
> Thanks

	$MY_VARIABLE=`ls -l`;

or as an array:
	
	@MY_VARIABLE=`ls -l`;

Brian Wheeler
bdwheele@indiana.edu



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

Date: 7 Apr 1998 15:12:25 -0700
From: smitty77@pacbell.net
Subject: Re: Simple Unix Question,  ( Simple for you maybe )
Message-Id: <6ge8c9$ktj@co-op.newsguy.com>

In article <6ge7ju$rv7$1@flotsam.uits.indiana.edu>, bdwheele@indiana.edu says...
>
>In article <1998040721474001.RAA25368@ladder01.news.aol.com>,
>	unixstuff@aol.com (UNIXstuff) writes:
>> 
>> From with a perl script.
>> I want to run the UNIX command ls -l
>> and have the info/string stored in a variable.
>> 
>> If I do
>> $MY_VARIABLE = system (ls -l);
>> 
>> $MY_VARIABLE is set to equal 0, which
>> is the unix return code for ls.
>> 
>> How do I get $MY_VARIABLE to eqaul
>> -rwxr-xr-x  1  root   sys   ..........   some_file_name
>> 
>> Thanks
>
>	$MY_VARIABLE=`ls -l`;
>
>or as an array:
>	
>	@MY_VARIABLE=`ls -l`;

The key here is to use backquotes around your UNIX command - this will execute
the command and place the results in the variable.  The first example places the
entire result in one scalar variable.  The second example places each line
separately into elements of an array.
Which method you choose depends on what you plan to do with the data.  If you
use the array method, you might want to do a chop on each line to get rid of the
newline.

Dave

>Brian Wheeler
>bdwheele@indiana.edu
>


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

Date: Tue, 7 Apr 1998 16:28:48 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Simple Unix Question,  ( Simple for you maybe )
Message-Id: <gq5eg6.qf7.ln@localhost>

UNIXstuff (unixstuff@aol.com) wrote:

: From with a perl script.
: I want to run the UNIX command ls -l
: and have the info/string stored in a variable.

: If I do
: $MY_VARIABLE = system (ls -l);
                 ^^^^^^

The very first paragraph of the description of system() in the 
'perlfunc' man page says how to capture the output of a command.


You didn't even try to read about system(), did you?

That's Not Good. 

Please try and be a responsible Usenet citizen in the future.


   $my_variable = `ls -l`;


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Tue, 07 Apr 1998 05:46:36 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Socket problems!
Message-Id: <35296b89.2948483@news.btinternet.com>

On Tue, 07 Apr 1998 02:56:17 +0200, Web-Hotel Danmark
<support@webhot.dk> wrote:

>Hi,
>
>I've tried for several days now to get e script to call a HTTP-server by
>using a socket-connection, 
<snip>

You will be delighted to learn that the LWP::* (libwww-perl) modules
from CPAN will do ,most probably, exactly what you want.

You will almost certainly also want to check out perlfaq9 which
addresses a number of these kind of things.

Have fun

/J\

Jonathan Stowe
See the MetaFaq at http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm


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

Date: Tue, 07 Apr 1998 16:43:28 -0500
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: Sorting in multi-line records.
Message-Id: <352A9E00.4994B591@us.ibm.com>

lawm@hotmail.com wrote:
> 
> Hi!
> I have the following problem..tried reading the faq..didn't help much.
> I have a text file  in the following format....
> 
> Header1
> Header2
> SEPARATOR (some string &l26a1H)
> .......6 lines
> Key ( text identifier used for sorting)
> .......n lines
> SEPARATOR
> .......6 lines
> Key
> .......n lines
> PATTERN get repeated a few thousand times
> EOF
> 
> What I want to do is get the separator and all the text till next separator
> into a large array for all separators till EOF
> Then sort this large arrays by Key, Key will be the first string in the 8th
> line of the array.
[snip]

Check the documentation and FAQ's for:
array of arrays
Schwartzian Transform
push
sort
The faq entry:
http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html#How_do_I_sort_an_aray_by_anyth

Maybe you could think of it this way...
Each block of text starting with a separator can be stored in an array. 
Each line in that block of text can also be stored in an array.  So
working backwards, we store each line we come to in an array that
represents a text block.  Then the text blocks are stored in an array
themselves.

@array[#number representing text block]->[#number representing line in
block]


#!/usr/bin/perl -w

$infile = "slop.txt";
$outfile = "clean.txt";
open IN,"$infile" or die "Can't open $infile $!";
open OUT,">$outfile" or die "Can't open $outfile $!";

$sep = "SEPARATOR";
$ctr = 0;  # Counts the number of text blocks found
@array = ();

# Ignore headers. ie start saving text at 1st instance of SEPARATOR
$line = <IN>;
while ($line !~ /$sep/) {
    $line = <IN>;
}

# $line contains our separator, so start saving text
# @array is an array of arrays

push @{ $array[$ctr] }, $line;
while ($line = <IN>) {
    last if $line =~ /^EOF$/;
    if ($line =~ /$sep/) {$ctr++;}
    push @{ $array [$ctr] }, $line;
}

# Now sort on n'th element of each @array element.  Don't forget to
start
# counting at 0 rather than 1.
$n = 8;
@sorted =
    map  { $_->[0] }
    sort { $a->[1] cmp $b->[1] }
    map  { [ $_, $_->[$n] ] } @array;

for (@sorted) {
    for (@{$_}) {
        print OUT $_;
    }
}

close IN or die "Can't close $infile $!";
close OUT or die "Can't close $outfile $!";


-- 
James Ludlow (ludlow@us.ibm.com)
This isn't tech support, and all opinions are my own.


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

Date: Tue, 07 Apr 1998 14:05:08 -0700
From: Ovanes Manucharyan <olm@mail1.csun.edu>
Subject: Sorting problem
Message-Id: <352A9503.96BB3A07@mail1.csun.edu>

I am having problems sorting ascii.
My sorting sub is included at the bottom. I got this off Tom
Christiansen's help page about sorting.

It works fine for numbers, but whenever I try to use it to sort other
ascii, it doesn't do it completely.

It's supposed to sort the array that is passed into it.

sub sortdata {
    @f = ();
        for (@biglist) { push @f, (split ':')[-1] }
        @new = @biglist[ sort { $f[$a] <=> $f[$b] } 0 .. $#biglist ];
    }

Can anyone help me?
--
----------------------------------------------------
Ovanes Manucharyan   olm@csun.edu
    California State University, Northridge
----------------------------------------------------




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

Date: Tue, 07 Apr 1998 14:46:54 -0700
From: Larry Rosler <lr@hpl.hp.com>
To: olm@mail1.csun.edu
Subject: Re: Sorting problem
Message-Id: <352A9ECE.DDDD1226@hpl.hp.com>

Ovanes Manucharyan wrote:
> 
> I am having problems sorting ascii.
> My sorting sub is included at the bottom. I got this off Tom
> Christiansen's help page about sorting.
> 
> It works fine for numbers, but whenever I try to use it to sort other
> ascii, it doesn't do it completely.
> 
> It's supposed to sort the array that is passed into it.
> 
> sub sortdata {
>     @f = ();
>         for (@biglist) { push @f, (split ':')[-1] }
>         @new = @biglist[ sort { $f[$a] <=> $f[$b] } 0 .. $#biglist ];
>     }
> 
> Can anyone help me?
> --
> ----------------------------------------------------
> Ovanes Manucharyan   olm@csun.edu
>     California State University, Northridge
> ----------------------------------------------------

Replace '<=>' by 'cmp'.

The '-w' flag would have told you explicitly what was wrong:

Argument "..." isn't numeric in ncmp at ... line ....

Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: Tue, 07 Apr 1998 23:16:18 +0100
From: Matt Pryor <matt@whiterabbit.co.uk>
To: olm@mail1.csun.edu
Subject: Re: Sorting problem
Message-Id: <352AA5B2.5CC0201E@whiterabbit.co.uk>

You need to use cmp for ascii comparisons.


> It works fine for numbers, but whenever I try to use it to sort other
> ascii, it doesn't do it completely.

-- 
http://www.whiterabbit.co.uk/design


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

Date: Mon, 6 Apr 1998 20:53:29 +0100
From: Rosemary I H Powell <Rosie@dozyrosy.demon.co.uk>
Subject: Re: Subscribing to a list without duplicates
Message-Id: <awYRkHA5KTK1EwMW@dozyrosy.demon.co.uk>

In article <35248032.2505914@news.saix.net>, Rod Borland
<rodb@dial.pipex.com> writes
>Can anyone help me? I am using perl to create a list of subscribers
>  8< snipped>8
>I do have access to the server logs so am programming blind and I do
>not get any error messages back.
>
>Rod Borland

Rod,

I had this same problem and someone told me how to route error messages
to the web page for debugging purposes, and I now use this technique
regularly.

Add these lines as close as possible to the top of your script, then
proceed as normal:

#=======================================================================
# redirect STDERR to STDOUT channel so we can see the die messages             
#=======================================================================
   open (STDERR, ">&STDOUT") || die "$0 Cannot redirect STDERR $! \n";

#=======================================================================
# unbuffer streams to get immediate print  
#=======================================================================
   select (STDERR); $| = 1; select (STDOUT); $| = 1;

#=======================================================================
# print the header now to enable us to display any error messages   
#=======================================================================
   print "Content-type: text/html\n\n";

This ensures that all messages display on the web page. If in addition,
you liberally spice the script with print statements, you will probably
not need to see any server logs... 

Best wishes,
Rosemary

-------------------------------------------------------------------
| Rosemary I.H.Powell  EMail: Home: rosemary@dozyrosy.demon.co.uk |     
|                             Work: r.i.h.powell@rl.ac.uk         |
|                       http://www.netlink.co.uk/users/dozyrosy/  |
|                       http://www.dozyrosy.demon.co.uk/          | 
-------------------------------------------------------------------


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

Date: 7 Apr 1998 21:26:47 GMT
From: "Lee Falkenhagen" <falkenl@hotmail.com>
Subject: Trying to Match two lists
Message-Id: <01bd626c$039aab60$915c5093@lfalkenhagen.dhs.state.tx.us>
Keywords: Perl, Lists, Matching

I have two lists of data that I have to match.  I want to make sure that
for every value in List A, this is a corresponding value in List B with the
same date as the rest of values in List A.

List A(array)	List B (list of files in directory)

KC101		980402.KC101
KC102		980402.KC102
KC103		980402.KC103
		980403.KC101
		980403.KC102

Since no match occurs on 980403 for KC103, I do not want to do any more
processing on it.  I am thinking that my result set should be the list of
dates.

Any help would be appreciated.

Thanks
Lee


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

Date: Tue, 7 Apr 1998 14:39:07 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Stas Bekman <sbekman@ilx374.iil.intel.com>
Subject: Re: Variable interpolation problems
Message-Id: <Pine.GSO.3.96.980407143354.1034L-100000@user2.teleport.com>

On Tue, 7 Apr 1998, Stas Bekman wrote:

> $abc = 345;
> $a = 'This is $abc';
> $b = eval {$a};

Eval can be evil. The Text::Template module gives a better way to do
things like this. Hope this helps! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 07 Apr 1998 05:46:49 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Web spider/crawler script
Message-Id: <3529bb58.13217261@news.btinternet.com>

On Tue, 07 Apr 1998 06:43:33 GMT, delphiask@sale-net.com.au (Peter)
wrote:

>Hi all. I am trying to find a spider or crawler type script I can use
>on a linux box. 

<snip>

The LWP::* (libwww-perl) modules available from CPAN give you the
facilities in combination with HTML::Parser to make one for yourself -
the excellent documentation that comes with LWP has some very good
examples. You might also peruse perlfaq9 for other networking examples
that might be of some use. 

/J\
Jonathan Stowe
See the MetaFaq at http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm


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

Date: Tue, 07 Apr 1998 05:46:47 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Win::ODBC, Using "GROUP BY" SQL to output
Message-Id: <3529af48.10350121@news.btinternet.com>

On Tue, 07 Apr 1998 10:53:58 -0600, webmistress@chicweb.com wrote:

<snip>

>Maybe there is a trick
>using Win::ODB I don't know about. Does anyone
>have any ideas?

Its not so much an ODBC thing as a perl thing as I see it,  you can
create a "GROUP BY" sort of  thing with a complex hash of a hash (of a
hash <etc as necessary>) it can get kind of gruesome looking if you
need a large number of groups.

For instance you might end up doing something like this on every row
returned by your query:

$ReportList{$ServerName}{$ReportName}($Weekend} = $ReportPath;

(Assuming I'd understood the order of your groups but you can see what
I mean I hope).

You can then do your "BEFORE GROUP OF" and "AFTER GROUP OF" (forgive
the terminology ) stuff whilst iterating over the keys of this hash in
a manner such as this:

foreach $server (sort keys %ReportList)
{
# title for server group here
    foreach $report (sort keys %ReportList{$server})
    {
     # title for report here
       foreach $weekend (sort keys %ReportList{$server}{$report})
       {
           $reportpath = $ReportList{$server}{$report}{$weekend};
        }
     }
} 

You might want to check out the perldsc document for more on this of
course: this is based on my totally ignorance of Win32::ODBC ;-}

>ps I thought I'd put "URGENT MESSAGE" in the subject but
>thought better of it when I saw the thread on the group. hahahaha
>

I havent decided whether to say "just as well" or "I wish you had" 

Have fun

/J\ 
Jonathan Stowe
See the MetaFaq at http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.  

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

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