[15574] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2987 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 9 03:05:32 2000

Date: Tue, 9 May 2000 00:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <957855911-v9-i2987@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 9 May 2000     Volume: 9 Number: 2987

Today's topics:
    Re: 2 decimal places? <gellyfish@gellyfish.com>
    Re: @array holding %hash <gellyfish@gellyfish.com>
    Re: Best way to connect to MS-SQL Server from Perl? atomshop@my-deja.com
    Re: converting input to <p></p> pairs via perl <gellyfish@gellyfish.com>
    Re: converting input to <p></p> pairs via perl <nospam@devnull.com>
    Re: converting input to <p></p> pairs via perl <uri@sysarch.com>
    Re: converting input to <p></p> pairs via perl <nospam@devnull.com>
    Re: converting input to <p></p> pairs via perl <uri@sysarch.com>
        efficiency with data separation. [was Re: HTTP::Request <nospam@devnull.com>
    Re: efficiency with data separation. [was Re: HTTP::Req <uri@sysarch.com>
    Re: efficiency with data separation. [was Re: HTTP::Req <nospam@devnull.com>
    Re: grep sender address from mail log <rootbeer@redcat.com>
    Re: Hang on uploading a file <rootbeer@redcat.com>
    Re: How can I declare variables in the command line at  <gellyfish@gellyfish.com>
        Is Perl fast enough? pohanl@my-deja.com
    Re: Making my script not case-sensitive! <gellyfish@gellyfish.com>
    Re: methods reading in external file bluesrift@aol.com
        Output user input to a plain text file <jcook@redgorilla.com>
    Re: Output user input to a plain text file <makarand_kulkarni@My-Deja.com>
    Re: parsing Unix mailbox <gellyfish@gellyfish.com>
    Re: perl in NT .BAT files Question philippe_cyk@my-deja.com
        signal trapper <andy@u2me3.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 7 May 2000 10:48:21 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: 2 decimal places?
Message-Id: <8f3e55$r9b$1@orpheus.gellyfish.com>

On Fri, 05 May 2000 14:08:11 GMT Dave wrote:
> Just wondered if someone
> could tell me how you get
> a calculation to say 2 decimal places?
> 
> e.g. 37.837    should come to 37.84
> 

You will find the answer (and much more) in perlfaq4 in the section :

       Does Perl have a round() function?

/J\
-- 
First you don't want me to get the pony, then you want me to take it
back. Make up your mind.
-- 
fortune oscar homer


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

Date: 7 May 2000 10:14:22 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: @array holding %hash
Message-Id: <8f3c5e$kp5$1@orpheus.gellyfish.com>

On 7 May 2000 02:02:37 GMT The WebDragon wrote:
> In article <MPG.137e675f184f4fdd98aa1b@nntp.hpl.hp.com>, Larry Rosler 
> <lr@hpl.hp.com> wrote:
> 
> I'm just curious, being a *gag choke* newbie to some pf the more elegant 
> ways that perl works. what is so 'tricky' about 
> 
>  | +         @{ $AoA[$i] } = @array; # way too tricky for most programmers
> 

It is dereferencing the LHS before assignment rather than taking a reference
to the RHS.

> and how and when would I use such a construct? 
> 

There are occasions when you might want to do that where you cant create a
new lexical variable within the scope you do this assignment and you need
to assign differing versions of @array to @AoA but generally one would want
to do :

  my @array;

  ....

  $AoA[$i] = \@array;

or even :

  $AoA[$i] = [ @array ];

If you dont want @array to be lexical for some reason.

> y'see I LIKE elegant tricky solutions to things :D

But please think about any maintenance programmers ...

/J\
-- 
Lurlee your song touched me in so many ways......and which way to the can?
-- 
fortune oscar homer


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

Date: Tue, 09 May 2000 04:15:53 GMT
From: atomshop@my-deja.com
Subject: Re: Best way to connect to MS-SQL Server from Perl?
Message-Id: <8f83dd$v5i$1@nnrp1.deja.com>

I have had good success using FreeTDS on a Linux box running SuSE 6.2.
The only trick is loading the right ver.  I used TDS 4.2 with
DBD::Sybase to connect to SQL Server 7 running on NT.

www.freetds.org should give you a start....

Here's some sample code...

$sql = "select......";
$dbh = DBI->connect("DBI:Sybase:IPAddress",'User','Pass');
($dbh->do("use DBName")!= -2) || error("The database <b>DBName</b>
doesn't exist");
                $sth = $dbh->prepare($sql);
                $sth->execute;

               while (@row = $sth->fetchrow_array()) {
                        $cnt++;
                        $co = $row[0];
                        }

In article <CcZQ4.100910$U4.838940@news1.rdc1.az.home.com>,
  "Tom Williamson" <tom.williamson@home.com> wrote:
> Hello -
>
> I'm looking for some information - facts and/or advice - on the best
way to
> connect to a SQL Server 7 database running on NT, from a Linux box
using
> Perl.  So far I have checked www.perl.org, www.perl.com and the CPAN
archive
> including the FAQs and the DBI/DBD readme files (those I have been
able to
> locate).   I have discovered the following:
>
> 1) There is not, so far as I can tell, a DBD::SQLServer module or
anything
> like it (why?);
> 2) The DBD::ODBC module (my second choice)  cheerfully announces
itself as
> "ALPHA SOFTWARE - YOUR MILEAGE MAY VARY".     Is there another (non-
alpha)
> module that people can use for ODBC?
>
> Is anyone out there actually interfacing Perl to SQL Server?   And
please -
> how are you doing it?  If you are using ODBC, how are you creating
your DSN
> on the Unix client box?
>
> Thanks....
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 7 May 2000 10:21:25 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: converting input to <p></p> pairs via perl
Message-Id: <8f3cil$m31$1@orpheus.gellyfish.com>

On 6 May 2000 23:35:10 GMT The WebDragon wrote:
> Larry, thanks again for the help with this, but after some further 
> testing, I can see that the output isn't exactly what I had in mind.. 
> 
> given default review text of 
> 

<snip>

> and the script snippet: 
> -=-
> use CGI::Pretty; 
> my(@reviewText, $reviewBody)
>   {
>     local $/ = ""; # Set 'paragraph mode' -- see perlvar.
>     @reviewText = map { chomp; "<p>$_</p>\n" } param('reviewtext');
>    }
> foreach (@reviewText) { s/\n/<br>\n/g };
> foreach (@reviewText) { $reviewBody .= shift(@reviewText) };
> 

You are not reading from a file so setting $/ has no effect in this context.

I think you mean :

$reviewBody .= map { "<P>\n$_</P>\n" } 
               map { s/\n/<BR>\n/g; $_ }
               split /\n\n/, param('reviewtext');

/J\
-- 
Beer. Now there's a temporary solution.
-- 
fortune oscar homer


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

Date: 9 May 2000 05:22:37 GMT
From: The WebDragon <nospam@devnull.com>
Subject: Re: converting input to <p></p> pairs via perl
Message-Id: <8f87at$qng$0@216.155.33.31>

In article <8f3cil$m31$1@orpheus.gellyfish.com>, Jonathan Stowe 
<gellyfish@gellyfish.com> wrote:

 | On 6 May 2000 23:35:10 GMT The WebDragon wrote:
 | > Larry, thanks again for the help with this, but after some further 
 | > testing, I can see that the output isn't exactly what I had in mind.. 
 | > 
 | > given default review text of 
 | > 
 | 
 | <snip>
 | 
 | > and the script snippet: 
 | > -=-
 | > use CGI::Pretty; 
 | > my(@reviewText, $reviewBody)
 | >   {
 | >     local $/ = ""; # Set 'paragraph mode' -- see perlvar.
 | >     @reviewText = map { chomp; "<p>$_</p>\n" } param('reviewtext');
 | >    }
 | > foreach (@reviewText) { s/\n/<br>\n/g };
 | > foreach (@reviewText) { $reviewBody .= shift(@reviewText) };
 | > 
 | 
 | You are not reading from a file so setting $/ has no effect in this 
 | context.
 | 
 | I think you mean :
 | 
 | $reviewBody .= map { "<P>\n$_</P>\n" } 
 |                map { s/\n/<BR>\n/g; $_ }
 |                split /\n\n/, param('reviewtext');
 

this returns 

    1 

as the result in $reviewBody

not exactly what I wanted, either. :)

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: Tue, 09 May 2000 05:57:40 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: converting input to <p></p> pairs via perl
Message-Id: <x7og6guuy5.fsf@home.sysarch.com>

>>>>> "TW" == The WebDragon <nospam@devnull.com> writes:

  TW> In article <8f3cil$m31$1@orpheus.gellyfish.com>, Jonathan Stowe 
  TW> <gellyfish@gellyfish.com> wrote:

  TW>  | I think you mean :
  TW>  | 
  TW>  | $reviewBody .= map { "<P>\n$_</P>\n" } 
  TW>  |                map { s/\n/<BR>\n/g; $_ }
  TW>  |                split /\n\n/, param('reviewtext');

dunderhead! why are you string appending a list from a map? i think you
mean to join the maps and just assign to $review_body

$review_body = join '', map { s/\n/<BR>\n/g; "<P>\n$_</P>\n" }
			    split /\n\n/, param('reviewtext') ;

i also combined the 2 maps into one. untested as well but it looks ok.
i have not been following this thread closely so i don't know the
problem description well other than something about html and paragraph
stuff.

  TW> this returns 1 as the result in $reviewBody not exactly what I
  TW> wanted, either. :)

gellyfish had too much guiness in his belly when he wrote that code.

:-)

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 9 May 2000 06:43:46 GMT
From: The WebDragon <nospam@devnull.com>
Subject: Re: converting input to <p></p> pairs via perl
Message-Id: <8f8c32$4hm$0@216.155.33.31>

In article <x7og6guuy5.fsf@home.sysarch.com>, Uri Guttman 
<uri@sysarch.com> wrote:

 | >>>>> "TW" == The WebDragon <nospam@devnull.com> writes:
 | 
 |   TW> In article <8f3cil$m31$1@orpheus.gellyfish.com>, Jonathan Stowe 
 |   TW> <gellyfish@gellyfish.com> wrote:
 | 
 |   TW>  | I think you mean :
 |   TW>  | 
 |   TW>  | $reviewBody .= map { "<P>\n$_</P>\n" } 
 |   TW>  |                map { s/\n/<BR>\n/g; $_ }
 |   TW>  |                split /\n\n/, param('reviewtext');
 | 
 | dunderhead! why are you string appending a list from a map? i think you
 | mean to join the maps and just assign to $review_body
 | 
 | $review_body = join '', map { s/\n/<BR>\n/g; "<P>\n$_</P>\n" }
 | 			    split /\n\n/, param('reviewtext') ;
 | 
 | i also combined the 2 maps into one. untested as well but it looks ok.
 | i have not been following this thread closely so i don't know the
 | problem description well other than something about html and paragraph
 | stuff.
 | 
 |   TW> this returns 1 as the result in $reviewBody not exactly what I
 |   TW> wanted, either. :)
 | 
 | gellyfish had too much guiness in his belly when he wrote that code.
 | 
 | :-)

hehe maybe.. however that code you wrote still doesn't do what I want.. 

this comes the closest, but still is not perfect. 

$reviewText = param('reviewtext');
$reviewText =~ s!\r\n?!\n!g;
$reviewText =~ s!\n!<br>\n!g;
$reviewText =~ s!(<br>\n){2,}!</p>\n\n<p>!g;
$reviewBody = "<p>$reviewText";

this basically produces the output of 

<p>Enter your comments separated by double-returns like normal 
paragraphs.</p>

<p>If you want lines to break</p>

<p>like this, then enter it that way.</p>

<p>The parser will automatically produce the correct paragraph and 
linebreak tags so please DO NOT enter them on your own... they'll get 
removed =)</p>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam 
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat 
volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation 
ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. 
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse 
molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero 
eros et accumsan et iusto odio dignissim qui blandit praesent luptatum 
zzril delenit augue duis dolore te feugait nulla facilisi.</p>

however that should read 

<p>If you want lines to break<br>
like this, then enter it that way.</p>

given the input : (simulating the newlines for you here cuz of the 
newsreader's linewrapping.. just remove the \n's manually prior to 
testing) 

#default text value
$reviewText = <<'EOM';
Enter your comments separated by double-returns like normal paragraphs.\n
\n
If you want lines to break\n
like this, then enter it that way.\n
\n
The parser will automatically produce the correct paragraph and 
linebreak tags so please DO NOT enter them on your own... they'll get 
removed =)\n
\n
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam 
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat 
volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation 
ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. 
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse 
molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero 
eros et accumsan et iusto odio dignissim qui blandit praesent luptatum 
zzril delenit augue duis dolore te feugait nulla facilisi.\n
EOM

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: Tue, 09 May 2000 07:04:10 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: converting input to <p></p> pairs via perl
Message-Id: <x7ln1kurvb.fsf@home.sysarch.com>

>>>>> "TW" == The WebDragon <nospam@devnull.com> writes:

  TW> this comes the closest, but still is not perfect. 

  TW> $reviewText = param('reviewtext');
  TW> $reviewText =~ s!\r\n?!\n!g;
  TW> $reviewText =~ s!\n!<br>\n!g;
  TW> $reviewText =~ s!(<br>\n){2,}!</p>\n\n<p>!g;
  TW> $reviewBody = "<p>$reviewText";

now that i have some sample input and incorrect and corrected output, i
can tackle this. but it will have to wait until tomorrow.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 9 May 2000 04:49:28 GMT
From: The WebDragon <nospam@devnull.com>
Subject: efficiency with data separation. [was Re: HTTP::Request=HASH(0x7bb141c) ?]
Message-Id: <8f85co$nah$0@216.155.32.184>

In article <87og6g4fur.fsf@shleppie.uh.edu>, Tony Curtis 
<tony_curtis32@yahoo.com> wrote:

 | Ahh, but what do you want to do with this URL?
 | 
 | The browser does a GET, that's what you have to do too.
 | 
 | my $request = new HTTP::Request GET => 'http......';

AHA! said the rabbit.. 

one other change I needed too (after a little reading) was 
$response->content; :) *chuckle* I also figured out that I needed to pop 
in the s!\r!!g; to remove any of the \r chars that come in there (for 
some reason they all come over DOS-formatted... evidently a IIS server. 
*biting my tongue*)  :^)

also added a check to the script to make sure it is able to grab all the 
files, and dies if not, with 

    die "$baseURL $_ failed: ",$response->error_as_HTML 
        unless $response->is_success;


The completed script as it stands now is at the bottom of this post, and 
it produces perfect output :) EXACTLY what I want! (THANK YOU for all 
your help so far, Folks.. this wouldn't nearly as much sheer fun for me, 
if it were not for your kind assistance! I'm enjoying the hell out of 
this.. seeing stuff I just learned how to do, work perfectly! :D 'tis 
quite exhiliarating. :)

if you want to test it yourselves, just comment out the appropriate part 
of the script. 

Next Question(2 parts): 

Ok, _now_ where I want to go with this, is twofold: 

=== #1 ===
 to re-generate some html output USING the freshly created maps_list.txt 
as if it were a master database. 

the maps_list.txt looks something like this: 

--BEGIN ut_assault_maps.htm --

"as-abraxasassault","AS-AbraxasAssault",1288,"as-abraxasassault",8 
"as-airportterror","AS-AirportTerror",922,"as-airportterror",4.5 
"as-asthenosphere","AS-Asthenosphere",2198,"as-asthenosphere",9 
[major snippage]
"as-ufr5-incursion","AS-URF5-Incursion",2201,"-1",-1 
"as-urbanassault","AS-UrbanAssault",2424,"-1",-1 

--END--

--BEGIN ut_capturetheflag_maps.htm --

"ctf-2fort","CTF-2Fort",221,"-1",-1 
"ctf-2fort5","CTF-2Fort5",781,"-1",-1 
[more snippage]

basically I need to parse every line that does not begin with -- or is 
only \n and separate them into their component comma-delimited fields.

the fields are : 
'official' name, zip filename, filesize, review file name, map rating 
below as ($name, $lcname, $size, $review, $rating)

These are currently being converted via javascript (see original 6 
files) into single lines under a table row consisting of (this isn't 
exactly perl _or_ html but you'll get the idea)

<tr>  
<td><a href="http://www.planetunreal.com/dl/nc.asp?nalicity/utother/'. 
$lcname . '.zip target=new><font size=2> $name </font></a></td>
<td align=center><font size=2> $size </font></td> 
<td align=center><font size=2> 
if (rating != -1) {<a 
href="http://www.planetunreal.com/nalicity/reviews/' . $review . '.html" 
target=new>' . $rating . '</a>'} 
if (rating == -1) {'N/A'); 
</font></td>
</tr> 

 ... ( and I'd also like to add a section header using <th>$Section</th> 
where $Section = the 'word' after BEGIN)

now, the output I can do easily with CGI.pm.. that's not the question, 
nor the problem.. I can handle that fine at this point. <grin>

I actually think that making it all Tables (which is how it's done now) 
is slowing this down ENORMOUSLY, as the browser has to generate the 
entire table before it can display the page.. I hope to change that, but 
may not be able to, since the columns have to flow properly. I might 
consider only doing a SINGLE <tr> and flowing each section down it's own 
<td align=left/centered> column.. thus having only 3 <TD>'s instead of a 
zillion of 'em. =:o 

the question is: 

"How do I take each relavant line of text, and separate it into the 
individual fields, in the most efficient manner, so that I can take that 
resultant info and generate a single html page with each section 
preceded by the section title as quickly as possible."

you don't have to supply ALL the code.. that's NOT what I'm asking .. :) 
I'm just prefacing the situation and my next stumbling block as clearly 
as I can. 

I mean for example I know I could loop through the .txt file, or I can 
read it in all at once and parse it in one fell swoop into an array of 
several dimensions... or what ever other way you can tell me about that 
would be more efficient/elegant. I haven't seen too much information 
about handling multi-dimensional arrays, so I dunno how practical or 
memory intensive that'd be. :/

Given that ultimately this section of code may be reused by me so that 
several hundred people simultaneously can view this cgi-generated html, 
it's obviously important that it be efficient. the text file is a little 
over 1400 lines now, and it _will_ continue to grow. I'll worry about 
using a popup menu/submit form to break the list apart into sections 
later.. right now I don't care if it displays the entire thing at once, 
as long as the fields and sections break properly. 

Eventually this 'grabbing' will go away, and I'll simply be outputting 
the html from the pseudo-database .txt file, anyway. This is just so I 
can keep my daily files up to date until we're able to switch over from 
the 'old way' (if this proves to be faster) (which it should).

=== #2 === 
to be able to feed it a list of the maps that I have downloaded as .zip 
files, and determine if any of those maps have not yet been rated. (i.e. 
have a -1 for their rating field entry) =:D (basically a quick 
comparison search)

(because I have to *write* reviews also -- this coding stuff is 
distracting me from _playing_ Unreal Tournament, so you can probably 
guess that this is quite fun for me, and I'm thoroughly enjoying myself 
thinking up things I can do that will help me to learn perl in the 
process. :)
=== ===

whew.. ok that was WAY too long-winded. Apologies for the huge post.. 
I'll try to cut things down in the future. :( 

Again though, TONS of THANKS, everyone, for the help up til now. :)

-=-begin script-=-
#!perl -w
use strict;
use diagnostics -verbose;
use LWP::UserAgent;
use File::Spec;

my $inputDir = File::Spec->catfile( File::Spec->curdir(), 'input_files', 
'');
my $baseURL = 'http://www.planetunreal.com/nalicity/';

#fixed fileslist
#my @filesList = (
#    'ut_assault_maps.htm',
#    'ut_capturetheflag_maps.htm',
#    'ut_dm_maps.htm',
#    'ut_dm_maps_b.htm',
#    'ut_domination_maps.htm',
#    'ut_other_maps.htm'
#);

#active fileslist
opendir(DIR, $inputDir) || die "can't opendir $inputDir: $!";
    my @filesList = readdir(DIR);
closedir DIR;

for (@filesList) {
    my $ua = new LWP::UserAgent;
    my $request = new HTTP::Request 'GET' => $baseURL . $_;
    my $response = $ua->request($request);
    die "$baseURL $_ failed: ",$response->error_as_HTML 
        unless $response->is_success;

    open(OUT, ">$inputDir$_") or die ('Aieeeeee');
        print OUT $response->content;
    close OUT;
};

my @dataList;
for (@filesList) {
    my $grabFile = $inputDir . $_;
    open(GRAB, "<$grabFile") or die ('Cannot open file ' . $grabFile . 
"$!");
#   print 'Successful open of '. $grabFile ."\n";
    push @dataList, "--BEGIN $_ --\n\n";
    while(<GRAB>) {
        s!\r!!g;
        next unless /^\Qmaps[i++] = new Map(\E([^)]+)/;
        push @dataList, "$1 \n" ;
    }
    push @dataList, "\n--END--\n\n";
    close (GRAB);
};

open(OUT, ">maps_list.txt") or die(' Cannot open output file ' . $!);
#   for (@dataList) { print OUT "$_" }
    print OUT @dataList;
close (OUT);
__END__
-=-end script-=-

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: Tue, 09 May 2000 05:48:57 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: efficiency with data separation. [was Re: HTTP::Request=HASH(0x7bb141c) ?]
Message-Id: <x7r9bcuvcp.fsf@home.sysarch.com>

>>>>> "TW" == The WebDragon <nospam@devnull.com> writes:

  TW> in the s!\r!!g; to remove any of the \r chars that come in there (for 

since you seem to like to learn stuff, get to know tr///. it is better
and faster than s/// for single character munging in many cases.

	tr/\r//d ;


  TW> "How do I take each relavant line of text, and separate it into the 
  TW> individual fields, in the most efficient manner, so that I can take that 
  TW> resultant info and generate a single html page with each section 
  TW> preceded by the section title as quickly as possible."

use a html template module (you have many to choose from). they will do
most of the work for you. just search cpan for the term 'template'.

  TW> #fixed fileslist
  TW> #my @filesList = (
  TW> #    'ut_assault_maps.htm',

use qw() for lists of tokens. it looks better and is easier to edit.


  TW> #active fileslist
  TW> opendir(DIR, $inputDir) || die "can't opendir $inputDir: $!";

  TW>     die "$baseURL $_ failed: ",$response->error_as_HTML 
  TW>         unless $response->is_success;

notice how you have the open first and die second? you should do the
same for the $response test. generally you emphasize the test which is
important and then the failure code. of course saying:

	next if /^$/ ;

is a common idiom. you should just be aware of which style you choose
for which kind of test and error handling pair.


  TW>     open(OUT, ">$inputDir$_") or die ('Aieeeeee');

good choice of die expression.

  TW> my @dataList;
  TW> for (@filesList) {
  TW>     my $grabFile = $inputDir . $_;

	my $grabFile = "$inputDir$_" ;

most people prefer "" to . with simple scalars. i reserve . for use with
function calls and in .= where it is very useful.




  TW>     open(GRAB, "<$grabFile") or die ('Cannot open file ' . $grabFile . 
  TW> "$!");

		 die( "Cannot open file $grabFile: $!" );

again, use double quotes for the die string. much simpler and cleaner

  TW> #   print 'Successful open of '. $grabFile ."\n";

ditto.

  TW>     push @dataList, "--BEGIN $_ --\n\n";
  TW>     while(<GRAB>) {
  TW>         s!\r!!g;

first, don't use odd delimiters unless you have to have / in the
expressions. second, i showed you the better way to do that before.

  TW>         push @dataList, "$1 \n" ;

why the space after $1? you won't see it on the screen. i have seen some
(who must remain nameless so they will stay away) use the excuse it
makes it easier to see the \n. balderdash! it is not needed and it can
be the cause of odd data bugs if you don't expect invisible trailing
blanks in your data.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 9 May 2000 07:02:45 GMT
From: The WebDragon <nospam@devnull.com>
Subject: Re: efficiency with data separation. [was Re: HTTP::Request=HASH(0x7bb141c) ?]
Message-Id: <8f8d6l$6qh$0@216.155.33.31>

In article <x7r9bcuvcp.fsf@home.sysarch.com>, Uri Guttman 
<uri@sysarch.com> wrote:

 | >>>>> "TW" == The WebDragon <nospam@devnull.com> writes:
 | 
 |   TW> in the s!\r!!g; to remove any of the \r chars that come in there 
 |   (for 
 | 
 | since you seem to like to learn stuff, get to know tr///. it is better
 | and faster than s/// for single character munging in many cases.
 | 
 | 	tr/\r//d ;

ok done. thanks for the tip :) 

 |   TW> "How do I take each relavant line of text, and separate it into 
 |   the 
 |   TW> individual fields, in the most efficient manner, so that I can 
 |   take that 
 |   TW> resultant info and generate a single html page with each section 
 |   TW> preceded by the section title as quickly as possible."
 | 
 | use a html template module (you have many to choose from). they will do
 | most of the work for you. just search cpan for the term 'template'.

the html is the EASY part.. it's parsing the INPUT that's my problem =:o 
Please re-read the previous post again! the script was NOT my problem.. 
I have stuff that has to come AFTER maps_list.txt is created! 

 |   TW> #fixed fileslist
 |   TW> #my @filesList = (
 |   TW> #    'ut_assault_maps.htm',
 | 
 | use qw() for lists of tokens. it looks better and is easier to edit.

so, like this?:
my @filesList = qw(
    ut_assault_maps.htm
    ut_capturetheflag_maps.htm
    ut_dm_maps.htm
    ut_dm_maps_b.htm
    ut_domination_maps.htm
    ut_other_maps.htm
);


 |   TW> #active fileslist
 |   TW> opendir(DIR, $inputDir) || die "can't opendir $inputDir: $!";
 | 
 |   TW>     die "$baseURL $_ failed: ",$response->error_as_HTML 
 |   TW>         unless $response->is_success;
 | 
 | notice how you have the open first and die second? you should do the
 | same for the $response test. generally you emphasize the test which is
 | important and then the failure code. of course saying:

true, but this works the way I think, and 'feels' perfectly normal.. 
TMTOWTDI :) 

 | 	next if /^$/ ;
 | 
 | is a common idiom. you should just be aware of which style you choose
 | for which kind of test and error handling pair.

ok, thanks. :)

 |   TW>     open(OUT, ">$inputDir$_") or die ('Aieeeeee');
 | 
 | good choice of die expression.

like I said, I'm having WAY too much fun with this.. :)

 |   TW> my @dataList;
 |   TW> for (@filesList) {
 |   TW>     my $grabFile = $inputDir . $_;
 | 
 | 	my $grabFile = "$inputDir$_" ;
 | 
 | most people prefer "" to . with simple scalars. i reserve . for use with
 | function calls and in .= where it is very useful.

I read something somewhere regarding variable interpolation within "" as 
opposed to the bare variable itself in the "Programming Perl" book and 
took it to heart. I don't recall offhand the exact reference, but I got 
the strong impression that the way I wrote it up there, was inclined to 
be more efficient.

 |   TW>     open(GRAB, "<$grabFile") or die ('Cannot open file ' . 
 |   $grabFile . 
 |   TW> "$!");
 | 
 | 		 die( "Cannot open file $grabFile: $!" );
 | 
 | again, use double quotes for the die string. much simpler and cleaner

Yeha, there I suppose I could. OK, I cleaned 'em up. 

 |   TW> #   print 'Successful open of '. $grabFile ."\n";
 | 
 | ditto.
 | 
 |   TW>     push @dataList, "--BEGIN $_ --\n\n";
 |   TW>     while(<GRAB>) {
 |   TW>         s!\r!!g;
 | 
 | first, don't use odd delimiters unless you have to have / in the
 | expressions. second, i showed you the better way to do that before.

well I did it because of suggestions on readability I've observed. 
There's nothing wrong inherently with the odd delimiters as long as it 
improves readability. Don't forget I'm still somewhat new at this and am 
trying to make MY life easier when I go back and look at these things 
later. :) 

 |   TW>         push @dataList, "$1 \n" ;
 | 
 | why the space after $1? you won't see it on the screen. i have seen some
 | (who must remain nameless so they will stay away) use the excuse it
 | makes it easier to see the \n. balderdash! it is not needed and it can
 | be the cause of odd data bugs if you don't expect invisible trailing
 | blanks in your data.

ok point taken. 

NOW.. go back to the original post, now that you've commented on the 
script, and re-read the questions I asked.. which you completely skipped 
over (why, I don't know).. 

to re-iterate: now that I've CREATED this data file 'maps_list.txt', I 
need to parse what it contains to produce further output, and I need to 
know some things regarding how best to do so!

please, re-read the previous post! :))

but thank you for the cleanup tips :)

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: Mon, 8 May 2000 21:15:27 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: grep sender address from mail log
Message-Id: <Pine.GSO.4.10.10005082114340.3921-100000@user2.teleport.com>

On Tue, 9 May 2000 fgerik@my-deja.com wrote:

> How do I grep sender's address (sender@foo.com) from within the < and >
> for example "from=<sender@foo.com>"

Probably with a pattern match. Do you know how to write a pattern in Perl?

> Is there a web site about processing sendmail log with perl ?

What do we look like, a search engine? :-)

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



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

Date: Mon, 8 May 2000 21:14:08 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Hang on uploading a file
Message-Id: <Pine.GSO.4.10.10005082111470.3921-100000@user2.teleport.com>

On Tue, 9 May 2000 siust@my-deja.com wrote:

> Everytime I try submiting any form with <INPUT TYPE=FILE,..> along with
> a valid non-existing filename, the CGI script will hang indefinitely.

Is it valid or is it non-existing? :-)

Well, I don't want to sound like I'm not helpful, but you should first fix
the problems with missing '-w', '-T', and 'use strict'. Then people around
here will be more willing to give you more help, since they'll see that
you're trying hard to fix the problems on your own.

Also, you may be able to get more or better help in a newsgroup about CGI
programming issues, such as comp.infosystems.www.authoring.cgi. Good luck!

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



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

Date: 7 May 2000 10:41:18 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How can I declare variables in the command line at Dos prompt?
Message-Id: <8f3dnu$ppk$1@orpheus.gellyfish.com>

On Thu, 4 May 2000 17:46:09 GMT Sid Malhotra wrote:
> Saddek Rehal wrote:
>>
>> How do I assign a value to $city in the command line when I start the
>> script. I tried: c:\apache\perl\bin> perl test.pl $city=Paris but
>> without success.
>>
> 
> Anything you pass as a command line argument is passed into the program
> into an array called @ARGV.
> 
> so you would use something like:
> 
> #!\apache\Perl\bin\perl.exe
> 
> $city = @ARGV;
> 
> print $city;
> exit;
> 
> 
> C:>perl test.pl paris
> Paris
> 

Er :

[gellyfish@orpheus clpmtest]$ perl argtest.pl Paris
1


I think you mean :

   $city = $ARGV[0];

or

   $city = shift;

whereas

   $city = @ARGV;

Will give you the number of arguments passed.

/J\
-- 
Dandyism is the assertion of the absolute modernity of Beauty.
-- 
fortune oscar homer


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

Date: Tue, 09 May 2000 04:14:13 GMT
From: pohanl@my-deja.com
Subject: Is Perl fast enough?
Message-Id: <8f83aa$v3l$1@nnrp1.deja.com>



Perl is a scripting language that basically has an interpreter
that goes through the code and follows the script.  It is my
understanding that there is a compilation stage where the script
is compiled into something that resembles bytecodes in java, and
the interpreter will then run the bytecode (am I correct on this?)
If this is the case then Perl has basically the same technology
as Smalltalk and Java.  Otherwise the script is not really compiled
into bytecode but basically processed into a more readable form
for the interpreter.  Bytecodes contain instructions for a
virtual machine cpu (like Load and Store operations in assembly).

I know in Java the Virtual machines is supposed to run a
garbage collector in the background (or when idle) to reclaim
memory used by unreferenced variables.  Early versions of the
VM simply allocated memory and didn't even bother to garbage collect
(the code for it wasn't even in there!)  I think the latest versions
have some sort of garbage collection built in.

Does perl have garbage collection?  When is it run?  Or if there
even is a garbage collector?  If it does exist, when does unreferenced
variables get garbage collected?  Right when they are not referenced?
Or does a background garbage collection comes around and frees up
memory when memory is low, or when it is idle, or checks periodically
now and then, or runs constantly in the background (don't know if
this is possible if multi-threads are not supported on some platforms).

The reason I am asking is, I created a neat perl program that
resembles a dynamic glossary.  It basically allows anyone to
enter a term and definition from a web-front end, and the terms
are recursive (if a definition contains a defined term, it will
be linked to that defined term).  In addition, it can be integrated
(its modular) with any perl program so ANY generated webpages can
have eGlossary'ed definitions.  I tied it to my discussion forums
and now any term someone enters into a message that is defined
in the glossary will be automatically linked to that term (url link).

You can check it out at http://www.edepot.com/religion.html
Pretty cool in my opinion.  Maybe I should release the code or
sell it.  Direct url to the glossary:
http://www.edepot.com/eglossary.html

But anyhow, because it is a dictionary type of perl program, it
uses a lot of memory and it does a lot of comparisons  (it will
need speed).  So I am guessing there is an upperlimit number
of glossary terms that it can handle before Perl cannot be used
anymore.  (In this case needing a c/c++ replacement).  Has anyone
ever created a memory intensive and speed sensitive application in
perl?  Can you comment on this?  Has anyone ever written a perl
program that crashed because of some upper bound in speed or
memory requirement?



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 7 May 2000 10:26:27 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Making my script not case-sensitive!
Message-Id: <8f3cs3$n11$1@orpheus.gellyfish.com>

On Sat, 06 May 2000 18:35:04 +0200 Ola Jetlund wrote:
> Tony Curtis wrote:
> 
>> >> On Sat, 06 May 2000 18:02:31 +0200,
>> >> Ola Jetlund <jetlund@tele.ntnu.no> said:
>>
>> > Hi, I'm using a script that reads all files in a
>> > directory and renames them.  I recently discovered that
>> > when I read the names of the files in the directory it
>> > skips all with capital letters (since my naming
>> > convention) uses small letters. I use the following code
>> > to read the directory:
>>
>> > Is there something I could do so the renaming also would
>> > happen when a file in the directory has an element that
>> > I have in my convention but with one or more large
>> > letters??
>>
>> I think you probably want the /i modifier for regexps, see
>> "perldoc perlre" but I find your post slightly confusing
>> so that may not be what you want.
>>
>> If you post code you need help/advice with, please post
>> *real* code otherwise people have to guess what you're
>> really trying to do, and the bits you snip usually turn
>> out to be where the problem lies :-)
>>
>> hth
>> t
> 
> Okay I'm sorry - but here is the a code bit that works:
> 
> 
> #!/usr/bin/perl
> opendir THISDIR, "." or die "Error: $!";
> @filer = readdir THISDIR;
> closedir THISDIR;
> @sfiles = sort(@filer);
> $for0 = "ola";
> $ett0 = "jetlund";
> $hel0 = "ola_jetlund";
> $i = 0;
> print "\n";
> foreach(@sfiles){
>     if(($_ =~ $for0) and ($_ =~ $ett0))

      if( /$for0/i  and  /$ett0/i )
 
>     {
#>          $i = $i + 1;
>          print "mv $_ ";

You probably want to use rename() instead.

/J\
-- 
When you participate in sporting events, it's not wether you win or
lose. It's how drunk you get.
-- 
fortune oscar homer


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

Date: Tue, 09 May 2000 06:25:25 GMT
From: bluesrift@aol.com
Subject: Re: methods reading in external file
Message-Id: <8f8b0b$72c$1@nnrp1.deja.com>

In article <8f645t$n8i$1@nnrp1.deja.com>,
  Ilja <billy@arnis-bsl.com> wrote:
> I guess you simply need to read the whole content of file into
$content.
>
> IMHO the simpliest (and most efficient way) is:
>
> undef $/;
> my $content = <FILE>;
>
> Please consult 'perldoc perlvar', section about $/ variable.

Thanks for the info! After having read the perldoc discussion of $/ I
can see how efficient it is to use the technique above. However, I
remain uncertain exactly how to set $/ back to the default newline
afterwards. Is it as simple as $/ = "\n";

Thanks,
Rob Bell

$/ The input record separator, newline by default. Works like awk's RS
variable, including treating blank lines as delimiters if set to the
null string. You may set it to a multicharacter string to match a multi-
character delimiter. Note that setting it to ``\n\n'' means something
slightly different than setting it to ``'', if the file contains
consecutive blank lines. Setting it to ``'' will treat two or more
consecutive blank lines as a single blank line. Setting it to ``\n\n''
will blindly assume that the next input character belongs to the next
paragraph, even if it's a newline. (Mnemonic: / is used to delimit line
boundaries when quoting poetry.)


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Mon, 8 May 2000 22:37:51 -0700
From: "James Cook" <jcook@redgorilla.com>
Subject: Output user input to a plain text file
Message-Id: <shf9h9do5uh35@corp.supernews.com>


I am trying to do 2 things with the following script, once the user fills
out the input

fields.
1)  Allow the user to view his/her input in on the same screen as the form
2) Output the user's input to a text file

I was able to get #1 to work, but number #2 is giving me problems.

##############Script####################################



#!/usr/local/bin/perl

use CGI qw(:standard);

print header;
print start_html('Fill out Form'),
    h1('Test'),
    start_form,
    "Field1: ",textfield('field1'),

    p,
    "Field2: ",textfield('field2'),
    p,
    "Field3: ",textfield('field3'),
    p,
    submit,
    end_form,
    hr;

if (param()) {

# attempting to post code to another file called "field.txt"

$FILE = 'field.txt';
open (FILE,"< $FILE") || die "Can't open $FILE: $!\n";
print header('text/plain');
print ("$field1\n");
print ("$field2\n");
print ("$field3\n");
}
close FILE;
    print
 "Field1",em(param('field1')),
 p,
 "Field2",em(param('field2')),
 p,
 "Field3",em(param('field3')),
 hr;
}








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

Date: Mon, 08 May 2000 23:03:45 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: Output user input to a plain text file
Message-Id: <3917AA41.3CBA67A5@My-Deja.com>

> print ("$field1\n");

should be

print FILE  "$field \n";
so that it goes inside the file.
--



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

Date: 7 May 2000 12:15:27 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: parsing Unix mailbox
Message-Id: <8f3j8f$fv2$1@orpheus.gellyfish.com>

On Sat, 06 May 2000 23:55:48 -0700 Christopher Adams wrote:
> I am just starting to plan a routine that will run something like this:
> 
> 1- Email messages will come into a Unix style mailbox. The subject of
> each message will have a unique string (a client's name/identifier).
> There will be a text file of email addresses, each address beginning
> with the unique string.
> 
> 2- Either each message will be parsed as it arrives, or the entire
> mailbox will be parsed at night (using cron). The message or mailbox
> will be queried for the unique string(name) and if it matches the string
> in the text file, the email will be forwarded to that address, adding
> some stock text to each one.
> 

I posted a program that does part of this yesterday.  Check Deja News if
you cant find it in your newsfeed.

/J\
-- 
The only thing that can console one for being rich is economy.
-- 
fortune oscar homer


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

Date: Tue, 09 May 2000 05:40:54 GMT
From: philippe_cyk@my-deja.com
Subject: Re: perl in NT .BAT files Question
Message-Id: <8f88d5$44e$1@nnrp1.deja.com>

Hi,

I have just uploaded a C-ISAM module on my website
Follow the link :

http:://www.oceanes.fr/~database/isampm.htm

Please mail me a bug report at philippe.cyk@wanadoo.fr

Hope this helps


In article <8erpfb$3lp$1@bob.news.rcn.net>,
  "BobS" <sturdevr@yahoo.com> wrote:
> I hate to disappoint those with long faces. If I knew enough about
Perl to
> write a C-ISAM module (or any other module), _I_ would cheer and
applaud in
> the streets. Maybe later ;-)
>
> Bob
>
> "Jonathan Stowe" <gellyfish@gellyfish.com> wrote in message
> news:8eppla$sv3$1@orpheus.gellyfish.com...
> > On Tue, 2 May 2000 13:34:52 -0400 BobS wrote:
> > > Thanks for the heads up. I'll keep that in mind. Since the
proprietary
> > > C-ISAM library does file access, my thought is to let Perl control
the
> file
> > > handler routines already in place. Hmmm, I wonder if Perl has a
C-ISAM
> > > module ...
> > >
> >
> > I dont think there is though If you were to write a DBI/DBD
interface to
> > the C-ISAM system you are using and submit it to CPAN I am sure
there
> > would be cheering and applause in the streets ;-}
> >
> > /J\
> > --
> > We'll die together, like a father and son should.
> > --
> > fortune oscar homer
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 7 May 2000 19:16:31 +0100
From: "Andy Chantrill" <andy@u2me3.com>
Subject: signal trapper
Message-Id: <8f4bst$1r6$1@neptunium.btinternet.com>

Hey,

Below is a very crude mock-up of a couple of sub-routines that I'm trying to
get working. It should basically trap INT and TSTP signals, and display a
status error to the user.

Copy-n-paste the code, run it, and hit [ctrl]+c, [ctrl]+z, and then do it
again - notice the errors are only displayed once, because it never breaks
out of the "signal_trapper" sub-routine, because as long as there is an INT
or TSTP signal coming from the user, the "status" sub-routine never ends and
returns back to the "signal_trapper" sub-routine (d'you know what I mean?):

--
#!/usr/bin/perl
&signal_trapper;
&status;

sub status {
 my($signal) = $_[0];
 if ($signal) {
  print "\nStatus:  A signal was caught ($signal)\n";
 }
 while (!$command) {
  print "Command: ";
  chomp($command = <STDIN>);
 }
}

sub signal_trapper {
 my($type) = $_[0];
 if ($type eq 'notify') {
  $SIG{INT}  = \&signal_trapper;
  $SIG{TSTP} = \&signal_trapper;
 } else {
  $signal = $type;
  &status($signal);
 }
}
--

I'll give a dollar to anyone who can make the signal trapper work,
preserving the structure as much as possible  :o)


Thanks, Andy.
andy@u2me3.com




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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 2987
**************************************


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