[10332] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3925 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 8 00:07:50 1998

Date: Wed, 7 Oct 98 21:00:24 -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           Wed, 7 Oct 1998     Volume: 8 Number: 3925

Today's topics:
    Re: Are there any "perl.newbie" group or forum? <uri@sysarch.com>
    Re: Are there any "perl.newbie" group or forum? <eashton@bbnplanet.com>
    Re: Are there any "perl.newbie" group or forum? (Craig Berry)
        Auto Reply via E-mail <aldisfu@i-2000.com>
    Re: Back button in Perl? (Marc Bissonnette)
        Chicago.PM meeting Monday, October 12 (Jim Allenspach)
    Re: Data Search Question (Snowhare)
    Re: Data Search Question dennis_marti@yahoo.com
        database problem..need urgent help!!!!!!! <sroque@man.amis.com>
        DBI/PostgreSQL <edwestfield@sprintmail.com>
    Re: DBI/PostgreSQL (Michael Fuhr)
        Difficulty with HTML & Perl & CGI <patheon@ns.net>
    Re: Extracting muliple values from a hash elund@compuserve.com
    Re: Extracting muliple values from a hash (Ronald J Kimball)
        Http post and SSL factor@imports.com
    Re: Making the date look good (Tom Tingdale)
        Need help refining this baillie@my-dejanews.com
    Re: pattern <gadget@bc.sympatico.ca>
    Re: Perl as a dumb terminal - rephrased <buxx@buxx.com>
        Perl Contractor Avaiable <Chris.OkuGami@worldnet.att.net>
    Re: Pizza Hut advertises for CPAN <dgris@perrin.dimensional.com>
    Re: Pizza Hut advertises for CPAN <rick.delaney@shaw.wave.ca>
    Re: Q: Speed up a regular expression (Ronald J Kimball)
        references becoming null pointers? rbowen@databeam.com
    Re: reg-exp: "Buy!!!" -> "Buy!" ? <gadget@bc.sympatico.ca>
    Re: scope of my using () (Ronald J Kimball)
        Searching a string.... <jstyles@hubcap.clemson.edu>
    Re: Searching a string.... (Larry Rosler)
    Re: Searching a string.... (Ronald J Kimball)
    Re: send geroge reese (was Re: Call for Participation:  (Abigail)
        strange problem with shift()... <psmith01@mindspring.com>
    Re: strange problem with shift()... (Ronald J Kimball)
    Re: Using Split and Join (Ronald J Kimball)
        What perl modules do I have??????? (Ken Williams)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 07 Oct 1998 22:22:36 -0400
From: Uri Guttman <uri@sysarch.com>
To: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Are there any "perl.newbie" group or forum?
Message-Id: <x7k92bu70z.fsf@sysarch.com>

>>>>> "RS" == Randal Schwartz <merlyn@stonehenge.com> writes:

>>>>> "Shambo" == Shambo Pfaff <shambop@bacon-and-spam.timeoutny.com> writes:

  Shambo> May the Schwartz be with you.

  RS> "looks like your schwartz is bigger than mine". :)


randal,

he was quoting from "spaceballs", mediocre star wars spoof by mel brooks.
but you probably knew that.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Thu, 08 Oct 1998 03:09:40 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Are there any "perl.newbie" group or forum?
Message-Id: <361C2A7A.C92E61DA@bbnplanet.com>

Uri Guttman wrote:

> he was quoting from "spaceballs", mediocre star wars spoof by mel brooks.
> but you probably knew that.

Uri, don't be such a dork ;) And it wasn't so mediocre. Mel rulez man! I
laughed :)
Blazing Saddles...who could forget? *giggle* May the schwartz be with
you ;). Daphne Zuniga as Princess Leia....The whole Hopi
motif....*sigh*, I'm too easily amused.

e.


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

Date: 8 Oct 1998 03:50:16 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Are there any "perl.newbie" group or forum?
Message-Id: <6vhcpo$54$1@marina.cinenet.net>

Uri Guttman (uri@sysarch.com) wrote:
: >>>>> "RS" == Randal Schwartz <merlyn@stonehenge.com> writes:
: >>>>> "Shambo" == Shambo Pfaff <shambop@bacon-and-spam.timeoutny.com> writes:
:   Shambo> May the Schwartz be with you.
: 
:   RS> "looks like your schwartz is bigger than mine". :)
: 
: randal,
: 
: he was quoting from "spaceballs", mediocre star wars spoof by mel brooks.
: but you probably knew that.

And so (nearly) was Randal.  I believe the original line, spoken by Lord
Dark Helmet, was "I see your schwartz is as big as mine...but do you know
how to use it?" :)

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      "Ripple in still water, when there is no pebble tossed,
       nor wind to blow..."


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

Date: Wed, 7 Oct 1998 23:29:31 -0400
From: "Tony" <aldisfu@i-2000.com>
Subject: Auto Reply via E-mail
Message-Id: <6vhbdn$ncp$1@news2.i-2000.com>

Hi,

How could I do an auto-reply via e-mail.

Why couldn't I use open(mail,"| telnet ppp.com 25");
What should I do if I wanted to do that?

Please help....thank you.

Tony




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

Date: 8 Oct 1998 03:13:26 GMT
From: dragnet@internalysis.com (Marc Bissonnette)
Subject: Re: Back button in Perl?
Message-Id: <6vhakm$ntm$1@news.interlog.com>

In article <6vgo99$ahh$1@client3.news.psi.net>, abigail@fnx.com says...
>

>Careful with telling me to be careful. Read my page, and specially
>the section "Adding a link back", and see why your suggestion isn't
>a back link at all.

Ok, I'll only be persistant and dense this once (yeah, I know, you believe 
me,too :)

What I was trying to say was that if Perl was spitting out the pages, it is 
possible to control the "back" feature via a link in the page. 

Each page must be written as a <FORM>
Each link has to be a submit-type button (Yes, this is ugly) or a radio / 
checkbox button. 
Each of these links must contain two bits of information, or one bit that the 
script can interpret as two: The destination link and the linking page. 

Actually, you could also follow the initial <FORM> tag with a hidden input tag 
stating the current page. So:

the script parses the form when sent back to the server. It reads the 
destination page, and the source page. 

As is spits out each line of text from the file to be printed, it looks for the 
one line containing the \back\ (or whatever identifiable pattern you wish to 
use) and replaces it with the name of the originating document. (this pattern 
is contained in the hyperlink for the back button on the page)

What I don't understand is why, using this method, you are suggesting you can't 
control the back feature? The script itself is controlling the content of the 
link. (in your page, yes, I did look at it and bookmarked it for all the info)

I'm convinced this will work (hell, it DID work for that mailer), but would be 
willing to write a simple script and html page or three to see if people can 
confuse it, if you're still saying this won't work.

I am keeping in mind, however, that this is extremely kludgy to do, makes for 
some unwieldy code and slows the process down, but if the original poster 
*really* has to do it....

-- 
Marc Bissonnette
InternAlysis
Corporate Internet Research and Results!
http://www.internalysis.com



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

Date: 7 Oct 1998 20:04:38 -0500
From: jima@MCS.COM (Jim Allenspach)
Subject: Chicago.PM meeting Monday, October 12
Message-Id: <6vh336$i0s@Mercury.mcs.net>


	The Chicago PM chapter will be having its next meeting on Monday,
October 12, at the Pick Me Up Cafe (3408 N. Clark), starting at 7:30 PM.
Information on the group or on how to get to the cafe can be found at the
group's Website, http://chicago.pm.org/ . 

jma



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

Date: 8 Oct 1998 01:24:17 GMT
From: snowhare@devilbunnies.org (Snowhare)
Subject: Re: Data Search Question
Message-Id: <6vh481$poc$1@nnrp3.snfc21.pbi.net>



Nothing above this line is part of the signed message.

In article <MPG.1085646c88e99fd69897f4@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>
>Benjamin Franz (Snowhare) posted an interesting geometrical approach 
>which might be competitive with linear search (but no code, 
>unfortunately).

Oh, if you insist. :) 

This is just the geometric search - I didn't include the linear
search switch over for datasets that are not appropriate to
the algorithm (sets where it takes fewer operations to do a linear
search than a geometric search - they can be detected fairly
easily, but I don't feel like writing the code for it today).

#!/usr/bin/perl -w

use strict;
srand;

# Initialize the data set
my $string_length = 4;
my $number_of_strings = 30000;
my %pseudo_array;
for (my $string_count=0;$string_count<$number_of_strings;$string_count++) {
	$pseudo_array{&gen_rand_string($string_length)} += 1;
}

my $search_string = &gen_rand_string($string_length);

# Do the search
&geometric_search($search_string,\%pseudo_array);

sub geometric_search {
	my ($search_string,$pseudo_array_ref) = @_;

	my $string_length = length($search_string);
	my %var_strings   = ($search_string => 1);
	my %matches;
	my $found         = 0;
	my $level         = 0;
	my ($key,$one);

	while ($level++ < $string_length) {
		while (($key,$one) = each %var_strings) {
			if (defined($$pseudo_array_ref{$key})) {
				$matches{$key} = $$pseudo_array_ref{$key};
				$found = 1;
			}
		}
		last if $found;
		&make_variant_strings(\%var_strings);
	}

	$level--;
	if ($found) {
		my $percent = int (100 * ($string_length - $level)/$string_length);
		print "Search String $search_string matched at the ",
			"$percent percent level.\n\nMatches:\n";
		while (my($key,$n) = each %matches) {
			for (my $count=0;$count<$n;$count++) {
				print " $key\n";
			}
		}
	} else {
		print "Hmmm. We didn't match at any level.......\n";
	}
}

sub make_variant_strings {
	my ($var_strings_ref) = @_;

	my @alphabet = ('A','B','C','D','E','F','G','H','I','J','K','L',
					'M','N','O','P','Q','R','S','T','U','V','W','X',
					'Y','Z');

	my (@strings) = keys (%$var_strings_ref);
	my $string;
	my $count;
	my $new_string;
	foreach $string (@strings) {
		my $string_length = length($string);
		while ($string_length--) {
			for	($count=0;$count<=$#alphabet;$count++) {
				$new_string = $string;
				substr($new_string,$string_length,1) = $alphabet[$count];
				$$var_strings_ref{$new_string} = 1;
			}
		}
	}
}

sub gen_rand_string {
	my ($string_length) = @_;

	my @alphabet = ('A','B','C','D','E','F','G','H','I','J','K','L',
					'M','N','O','P','Q','R','S','T','U','V','W','X',
					'Y','Z');
	my $rand_string = '';
	while ($string_length--) {
		$rand_string .= $alphabet[int(rand(26))];
	}
	$rand_string;
}

Benjamin Franz


Version: 2.6.2

iQCVAwUBNhwUPOjpikN3V52xAQHtsQP8Dd/WWQq7ja1C/NpwnPeY372sPEub3CgZ
ZlgK/TuORVWGz/VSAk0Wx/cZkCOa4buFwmFvUJf1Mp9a4dbbtnezKIj8+ZWtZ7ME
SeoQbBfQvLRP4LnXvko0aOQk1UMmPlmxgAlRsxBp+GTa2oVOOAh7gUFBeVx/AJIH
O5I2rvQI6K8=
=uT0E
-----END PGP SIGNATURE-----


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

Date: Thu, 08 Oct 1998 01:58:07 GMT
From: dennis_marti@yahoo.com
Subject: Re: Data Search Question
Message-Id: <6vh67f$mcf$1@nnrp1.dejanews.com>

In article <MPG.1085646c88e99fd69897f4@nntp.hpl.hp.com>,
  lr@hpl.hp.com (Larry Rosler) wrote:

> No, it is 20MB more!  In my code, the 1000000 strings are processed one-
> at-a-time, instead of all being in an array in memory.  Furthermore, my
> code examines each string just once, whereas the entire array is searched
> 10 times in John's code.
>
> My loop (strings in a data file):
>
>   while (<DATA>) {
>     my $xor = $_ ^ $datum;
>     next unless (my $n = $xor =~ tr/\0//) > $max;
>     $best = $_;
>     last if ($max = $n) == length $datum;
>   }
>

The original post said, "the match, though, must be based on PER CHARACTER
comparison - not the string as a whole." With an input string of 'UQPALRIEOF'
I think that would make 'RIEOFUQPAL' one of the best possible matches (10 of
10 characters). The loop above doesn't find it.

Since I can't even load 1_000_000 10 character strings into an array on this
box, this also goes through the file a line at a time.

#!/usr/bin/perl -w

$word = "UQPALRIEOF";
@word = split //, $word;

$eval_top = q(
    $best = 10;
    while (<>) {
        chop;
        $line = $_;
);

foreach $c (@word) {
    $eval_middle .= "s/$c//;\n"
}

$eval_bottom = q(
        if ($best > length) {
            $best = length;
            $match = $line;
            last if $best == 0;
        }
    }
    printf "%s matched %d characters\n", $match, 10-$best;
);

eval "$eval_top $eval_middle $eval_bottom";

__END__


Removing characters from a temporary string translates pretty easily to C and
makes it about 10 times faster than my perl, but it still reads a line at a
time from a file instead of answering the data structure question.

Dennis

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 8 Oct 1998 02:18:48 GMT
From: "AMIP" <sroque@man.amis.com>
Subject: database problem..need urgent help!!!!!!!
Message-Id: <01bdf261$4bc2a980$2bbe10ac@amipnet>

what does this error mean?

Can't locate database.sub in @INC


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

Date: Wed, 7 Oct 1998 20:37:22 -0500
From: "E Westfield" <edwestfield@sprintmail.com>
Subject: DBI/PostgreSQL
Message-Id: <6vh52q$iic$1@oak.prod.itd.earthlink.net>

Greetings

I am having problems grasping how to interface the postgresql database into
a perl script using the DBI.    I am not a perl programmer, but have
programmed in other Intel and mainframe languages.  I just don't see what I
am missing.  If someone could do a code snip of a simple connect to a
database on a server, execute a simple sql query, and then handle the
return, then disconnect, I would be grateful forever.
--
E Westfield
SCRIBE Network Coordinator
http://www.faire.net/SCRIBE




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

Date: Thu, 08 Oct 1998 03:05:29 GMT
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: DBI/PostgreSQL
Message-Id: <6vha5e$31n@flatland.dimensional.com>

"E Westfield" <edwestfield@sprintmail.com> writes:

> I am having problems grasping how to interface the postgresql database into
> a perl script using the DBI.    I am not a perl programmer, but have
> programmed in other Intel and mainframe languages.  I just don't see what I
> am missing.  If someone could do a code snip of a simple connect to a
> database on a server, execute a simple sql query, and then handle the
> return, then disconnect, I would be grateful forever.

#!/usr/local/bin/perl -w

use DBI;
use strict;

my $dbh = DBI->connect("dbi:Pg:dbname=mydatabase", "username", "password",
                       {"RaiseError" => 1});

my $sth = $dbh->prepare("select * from mytable");
$sth->execute;

while (my @row = $sth->fetchrow_array) {
	print "@row\n";
}

$sth->finish;

$dbh->disconnect;

-- 
Michael Fuhr
http://www.fuhr.net/~mfuhr/


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

Date: Thu, 08 Oct 1998 03:53:10 GMT
From: "John A. Miller" <patheon@ns.net>
Subject: Difficulty with HTML & Perl & CGI
Message-Id: <361C3750.C238AA7F@ns.net>

Greetings:

I have written several HTML pages using Perl. But I have had to spell
everytkhing out.  I would like to be able to use some of the short cuts
like query->header() but I can't figure out how to do it correctly.  (I
am using Omni HTTPD v2.0 as my web server on an NT machine)

I have been having a lot of trouble trying to get the following to work:

---------------------------------- Begin
Script----------------------------------
#!/usr/bin/perl

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
$query = new CGI;
print $query->header();
print $query->start_html(-TITLE=>'No Title',-BGCOLOR=>'white');
print "<H4><CENTER>Testing 4...</CENTER></H4>";
print $query->end_html;
---------------------------------- End
Script----------------------------------

It gives me the infamous "Document Contains No Data" error. I can
however write the same thing by spelling everything out and the page
works. I have used this successfully:
---------------------------------- Begin
Script----------------------------------
#!/usr/bin/perl

print "Content-type: text/HTML\n\n";
print "<HTML> ";
    print "<HEAD> ";
        print "<TITLE></TITLE>";
    print "</HEAD>  ";
    print "<BODY>   ";
        print "<H1>Testing 1...</H1>";
    print "</BODY>";
print "</HTML>";
---------------------------------- End
Script----------------------------------

If I comment out the first two lines...
##use CGI qw(:standard);
##use CGI::Carp qw(fatalsToBrowser);

I get no errors.  But it also doesn't write anything.  What am I doing
wrong?

Thanks,
John
patheon@ns.net



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

Date: Thu, 08 Oct 1998 01:04:22 GMT
From: elund@compuserve.com
Subject: Re: Extracting muliple values from a hash
Message-Id: <6vh32m$h7i$1@nnrp1.dejanews.com>

In article <MPG.10855a4e500a19fa9897f3@nntp.hpl.hp.com>,
  lr@hpl.hp.com (Larry Rosler) wrote:
> Hash slices such as this *are* in Perl and work just fine for everyone
> else.  Please post some code that makes you think they don't work for
> you.
>

Thanks for your replies.  I'm so sorry -- I was using references to hashes
and got the syntax wrong.  I didn't give it a second thought that I was
slicing off of a hash ref instead of a hash.  It's my fault for posting
something which didn't match my code.  Apologies.

I had:
  $hashRef = {a=>1, b=>2, c=>3};

And assumed I could do:
  @hashRef->{a,c};

Which didn't work.  What I later got to work is:
  @$hashRef{a,c};

I'm not certain why the latter works and not the former, but I'm glad it is at
least possible.  Again, sorry for the lack of accurate code.

Thanks again,
-- Eric

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 7 Oct 1998 23:47:38 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Extracting muliple values from a hash
Message-Id: <1dgjy8e.1cfyak4qay04sN@bay1-248.quincy.ziplink.net>

<elund@compuserve.com> wrote:

> I had:
>   $hashRef = {a=>1, b=>2, c=>3};
> 
> And assumed I could do:
>   @hashRef->{a,c};

That refers to the variable @hashRef, rather than $hashRef.

> Which didn't work.  What I later got to work is:
>   @$hashRef{a,c};

That's the right way to do it.  You might want to be more explicit,
however, and write

@{$hashref}{a,c}

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 08 Oct 1998 03:21:22 GMT
From: factor@imports.com
Subject: Http post and SSL
Message-Id: <6vhb3i$uae$1@nnrp1.dejanews.com>

I apologize if this problem has already been discussed here.  I'm sure it is a
common problem...

I'm trying to create a Perl script that will query another cgi using an HTTP
POST method.  The script will post some variables to the other cgi, and then
analyze the returned html page to take further action.	I can get this script
to work just fine using a standard http:// url to the cgi that is being
queried, but this script will not work when dealing with the other cgi if it
is an https:// url trying to use a SSL session.

For example, let's say there is a search cgi that will look up the current
price of a stock quote.  The url for this cgi is http://www.someserver/cgi-
bin/stocks, and the only variable it needs is "stocksymbol".  We then have a
script that we will submit two pieces of data to - a stock symbol, and a
price. This script will then pass the stocksymbol value to the search cgi
using an http post.  The script will then retrieve the resulting html page
and search it for the existence of the price we are looking for.  If the
stock quote does not result in the price we were looking for the script would
return "Price is not met".  If this price did exist on that returned html
page, then the script would return "Price matches."

Ok, so this was a very elementary example. :)

The current script I am creating works *perfectly* for the example above.  The
problem happens if the search cgi url is https://www.someserver.com... instead
of just http://. I am not too familiar with creating SSL socket connections,
and herein lies my problem.

I have read several posts concerning "SSLeay" and some other things that
should be the answer I'm looking for, but I am clueless at this point. :)

I guess my questions are: what are my options to simulate this SSL connection
to make this work, and what servers will this process not work on - i.e. a web
server without SSLeay installed or some other mod.

Ideally, I would like for this script to be able to work from any Linux web
server.

Any help with this would be sincerely appreciated.  Please email me at
factor@my-dejanews.com.

Thanks!

~John

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Thu, 08 Oct 1998 01:27:34 GMT
From: tingdale@flash.net (Tom Tingdale)
Subject: Re: Making the date look good
Message-Id: <361c1438.1136250@news.flash.net>

The Perl/CGI Cookbook has a great routine that will format date and or
time according to parameters you past it. VERY flexible. My book is at
work and I don't remember their website address. It was published Jan
1998. Maybe someone else will remember, otherwise look it up at 
www.amazon.com.

Tom

On Tue, 6 Oct 1998 17:28:58 -0500, "brettr" <brettr@centuryinter.net>
wrote:

>How can I convert something like this "10/06/98 06:41:13 CDT" into something
>like this "Tuesday, October 06, 1998"?
>
>brettr
>

tingdale@flash.net


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

Date: Thu, 08 Oct 1998 03:08:06 GMT
From: baillie@my-dejanews.com
Subject: Need help refining this
Message-Id: <6vhaam$srn$1@nnrp1.dejanews.com>

I was hoping someone could help me to refine this script (to make it a little
more perl-like and a little less shell-like).  If you'd like to run it to see
how it works there's a file that accompanies it which I'll send on request,
but here is the program(script, whatever):

Basically, this is my first perl program, and I'd like to have it more compact
(in the tradition of perl), as well as optimize it some.  Any help would be
appreciated!


#!/usr/bin/perl -w

  # figure out what host we're acting on and
  # run the command to an output file from that host
if(defined($ARGV[0])) {
        $host=$ARGV[0];
        system "rsh $host alex-sched -LP 0 > /tmp/opck.cache";
} else {
        $host='localhost';
        system "alex-sched -LP 0 > /tmp/opck.cache";
}

open(FILE, "/tmp/opck.cache")
                or die "Can't access file: $!";

$i=0;
  # Find the only instance of Total..Backup and
  # the last (can someone tell me how to get only
  # the last without saving an @ and referencing
  # the final value) instance of Current..Stored
while(<FILE>) {
        if(/^Total Bytes to Backup/) {
                chomp($to_store=$_);
                $to_store=~tr/[a-z A-Z:]//d;
                $to_store/=1024;
        }
        if(/^Current KBytes Stored/) {
                chomp($store_array[$i]=$_);
                $i++;
        }
}

close(FILE) or warn "Couldn't close file: $!";

  # Use the last value of the array for the current
  # amount of data that's been stored
$amount_stored=$store_array[$#store_array];
  # Is this (below) right?..to grep out only the numbers
$amount_stored=~tr/[a-z A-Z:]//d;
undef(@store_array);
undef($i);
$cntr=2;
$screen_width=`tput cols`;
$percentage=($amount_stored/$to_store)*100;
$vis_disp=($amount_stored/$to_store)*$screen_width;

printf "\t$host amount to store\t=\t%.0f\n", $to_store;
print "\t\tamount stored\t\t=\t$amount_stored\n";

for($cntr=0; $cntr<=$vis_disp; $cntr++) {
          # A little system curses-based output
	  # How can I do this in perl
	system "tput smso";
        print "=";
}

print ">\n";
system "tput rmso";
system "tput bold";
printf "\t\t\t\t\tOpcard is%2d", $percentage;
system "tput rmso";
print  "% complete\n\n";

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 07 Oct 1998 18:26:14 -0700
From: Fred Richards <gadget@bc.sympatico.ca>
To: Bob Lockie <bjlockie@nortel.ca>
Subject: Re: pattern
Message-Id: <361C14B6.76EF020@bc.sympatico.ca>



Bob Lockie wrote:

> I need to seach for the text "HEADER END]", throw away
> the lf/cr at the end, keep "---" in a variable (to the end of line),
> put the remainder "yyy...zzz" in a variable.
>
> [HEADER END]^M
> ------------------------------907796590328
> yyy
> zzz
>
> I have tried the pattern
> ($junk, $data) = $input_data
>      =~ /\[HEADER END\](\n|r\n)((.*(\n|r\n))*)/m;
>
> but no luck.
>
> Any of the ends of lines could be line feeds or crlf's (including the
> ^M).

Try this:

$input_data = "[HEADER END]\r\n------------------------------907796590328";

print $input_data, "\n";

my ($junk, $data) = $input_data =~ /(\[HEADER END\])[\r\n|\n]\D*(\d+)/s;

print "junk = $junk\ndata = $data";


Will pull out [HEADER END] and 907796590328 from $input_data;

Hope this helps.

Fred Richards
The Gadget Guy






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

Date: Wed, 07 Oct 1998 20:22:20 -0500
From: Buxx <buxx@buxx.com>
Subject: Re: Perl as a dumb terminal - rephrased
Message-Id: <361C13CC.2FD@buxx.com>

Buxx wrote:
> 
> I'm needing to interface a pc thru a serial port to a Meridian phone
> system to moniter and issue commands. All ascii text and emulating a
> dumb terminal.
> 
> Anyone have any words of wisdom or done such a thing ??
> 


I need to write a menuing program to replace the command line command
using Perl using a serial port as STDIN/STDOUT. Perl makes a great text
parser for this purpose, however I have no experience using the serial
port as STDIN/STDOUT. The Meridan Phone sys is highly cryptic and
requires a several volumes of docs to work with it.  Would like to
simlipfy basic operations using a perl based menu program.


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

Date: 8 Oct 1998 02:48:33 GMT
From: "Chris OkuGami" <Chris.OkuGami@worldnet.att.net>
Subject: Perl Contractor Avaiable
Message-Id: <6vh961$8to@bgtnsc02.worldnet.att.net>

Hi,
I am resident in Massachusetts and looking for
small project. If you need a help, let me know.

CHRIS





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

Date: Thu, 08 Oct 1998 02:28:05 GMT
From: Daniel Grisinger <dgris@perrin.dimensional.com>
Subject: Re: Pizza Hut advertises for CPAN
Message-Id: <m390irkd3i.fsf@perrin.dimensional.com>

cberry@cinenet.net (Craig Berry) writes:

> And conversely, how many Perl users downloading the latest revision of
> Text::YetAnotherFormattingThingy.pm will be seized with a sudden and
> overwhelming desire to order a pizza...no, wait, my god, that's happening
> already!

    my $stomach = 'is growling';
    require 'pizza';  use phone;

    $hurry = phone -> order('pizza', [ 'sausage',
                                       'pepperoni',
                                       'onion' ]);
    $OH_NO = add_to_order ( ($cheese ** $cheese) ** $cheese);

    wait for $pizza;

    open BOX, $pizza;

    die 'starving' if $has_anchovies;   # :-(

    fork if $deep_dish;                 # yummy

    do { chew() and swallow() } while $pizza;

    die 'happy';

dgris
-- 
Daniel Grisinger           dgris@perrin.dimensional.com
`Bangladesh.  Because life is too short to run bad code.'
                               Jon Orwant


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

Date: Thu, 08 Oct 1998 03:28:56 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Pizza Hut advertises for CPAN
Message-Id: <361C3305.4A54E9AB@shaw.wave.ca>

Daniel Grisinger wrote:
> 
>     open BOX, $pizza;
> 
>     die 'starving' if $has_anchovies;   # :-(

Always, always, ALWAYS check the success of open, even when your script
is just an example!  (Sorry, couldn't resist.)

Suggested alternative:

    open BOX, $pizza or die 'starving';

    return if $has_anchovies;

Add this to the FAQ!  

    I can't stop writing Perl.  How do I sustain myself?

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Wed, 7 Oct 1998 21:43:43 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Q: Speed up a regular expression
Message-Id: <1dgjsoo.1y8argr2lcdomN@bay1-244.quincy.ziplink.net>

Steven Lembark <lembark@wrkhors.com> wrote:

> > if ($line =~ /(^$Search )|( $Search )/io)
>
> probably faster as
> 
>   $line =~ /^$blah/ || $line =~ / $blah/
> 
> the first one can 
> short circut the second if they are separate regexes; with 
> an or-ed regex you end up having to search for both before 
> deciding what's correct.
> 
> check the camel book's section on performance for a few more
> tips.  there's also jeff friedl's book on regexes: has quite
> a thick section on perl (around 1/2 the book).

When you get a chance, I suggest that you read Jeff Friedl's book on
regexes.  Your assertion that in the single regex both alternatives must
be searched for is incorrect.  The second alternative will be searched
for only if the regex engine is forced to backtrack because the first
leads to an unsuccessful match later in the regex.

[Note: some regex implementations *would* try all alternatives before
choosing a match, because they want to always find the longest possible
match.  Perl's regex implementation does not operate that way.]

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 08 Oct 1998 03:27:42 GMT
From: rbowen@databeam.com
Subject: references becoming null pointers?
Message-Id: <6vhbfe$uto$1@nnrp1.dejanews.com>

I posted this once already, but discovered that our NNTP server is dead.
Hopefully this will only go out once. Anyways, I am finding that references
that I think are pointing to something end up pointing at nothing. I expect
that this is something to do with scope that I am just not aware of, so any
assistance would be greatly appreciated. Or, it could be something strange
with Msql, since I don't recall seeing anything similar elsewhere. Here is
the simplest piece of code that reproduces the problem that I am seeing:

#!/usr/bin/perl
use Msql;
$dbh = Msql->connect("",database);
        $sth = $dbh->query("select * from table");

        while (%hash = $sth->fetchhash())      {
                #  Based on some condition ...
                push @data, \%hash;
        }  #  End while
print @data;
for (@data){
        print keys %$_;
}

The output from this program is some lines like:
HASH(0x81191d0)
Indicating (to me, at least) that the array contains one or more hash
references, but that those references are not actually pointing at anything.

BTW, I am running 5.004_03 on Linux. I know, I should upgrade, but I am not
the sysadmin on the machine in question, and don't have mSQL on other servers
that I have access to.

 ... And, just before I pressed the "Post" button, I discovered that if I
change the above to read as below, things work (as in, I get the expected
keys for the hashes). Any explanations?

#!/usr/bin/perl
use Msql;
$dbh = Msql->connect("",database);
        $sth = $dbh->query("select * from table");

        while (%hash = $sth->fetchhash())      {
                %foo = %hash;
                #  Based on some condition ...
                push @data, \%foo;
        }  #  End while
print @data;
for (@data){
        print keys %$_;
}

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 07 Oct 1998 18:36:22 -0700
From: Fred Richards <gadget@bc.sympatico.ca>
To: Alex Farber <alex@kawo2.rwth-aachen.de>
Subject: Re: reg-exp: "Buy!!!" -> "Buy!" ?
Message-Id: <361C1716.5DDF93B@bc.sympatico.ca>

Alex Farber wrote:

> Hi,
>
> here is a regular expression quiz for you:
> How do you change the annoying repeating "!!!"
> (in a web board ;-)  to a single "!" ?
>
> Thanks in advance
> Alex
>
> --
> http://www.simplex.ru/pref.html

Try this:

$test = "Buy !!!";

print "$test\n";

$test =~ s/!+/!/;

print "$test\n";


The '+' means match one or more times.


Live long and party.

Fred Richards
The Gadget Guy



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

Date: Wed, 7 Oct 1998 21:43:47 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: scope of my using ()
Message-Id: <1dgjt0a.gz0g3w14qah2uN@bay1-244.quincy.ziplink.net>

[posted and mailed]

AmD <due@whitecrow.net> wrote:

> In one of my scripts a subroutine
> parses data from a file and creates a hash from the information.  This hash
> is then used to in making modifications to other files.  However, under
> certain, unpredictable, conditions the subroutine may fail in which case the
> hash returned from the subroutine will be undefined.

I think you mean that the hash returned from the subroutine will be
*empty*.  If that's the case, you can check if the subroutine was able
to create the hash successfully like so:

scalar(keys %hash)

That will give you the number of keys in %hash.  If it's 0, then the
hash is empty.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Wed, 7 Oct 1998 21:45:37 -0400
From: Styles <jstyles@hubcap.clemson.edu>
Subject: Searching a string....
Message-Id: <Pine.SOL.3.96.981007214117.27212A-100000@hubcap.clemson.edu>

Hello,

Is there a way to search a string starting from right to left instead of
left to right? 

Styles



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

Date: Wed, 7 Oct 1998 20:07:52 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Searching a string....
Message-Id: <MPG.1085cc6131a1ef979898a5@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <Pine.SOL.3.96.981007214117.27212A-100000@hubcap.clemson.edu> 
on Wed, 7 Oct 1998 21:45:37 -0400, Styles <jstyles@hubcap.clemson.edu> 
says...
> Is there a way to search a string starting from right to left instead of
> left to right? 

How about this:

    reverse($string) =~ /whatever pattern you want/;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 7 Oct 1998 23:47:40 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Searching a string....
Message-Id: <1dgjyfb.1yh1rf11e3jjizN@bay1-248.quincy.ziplink.net>

Styles <jstyles@hubcap.clemson.edu> wrote:

> Is there a way to search a string starting from right to left instead of
> left to right? 

What do you mean by 'search'?  Pattern matching?  index()?

Please give an example of what you want to do.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 8 Oct 1998 01:25:33 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: send geroge reese (was Re: Call for Participation: Python Conference)
Message-Id: <6vh4ad$5g7$1@client3.news.psi.net>

Zenin (zenin@bawdycaste.org) wrote on MDCCCLXIII September MCMXCIII in
<URL:news:907802725.854123@thrush.omix.com>:
++ Abigail <abigail@fnx.com> wrote:
++ 	>snip<
++ : Granted, if you want to use OO just because you like to use identical
++ : function names in very long but different packages, Perl's OO might be
++ : nice for you.
++ 
++ 	It's not quite a "just", but it is one of a number of reasons to
++ 	use OO without inheritance.
++ 
++ : I would redesign my software if it came to that.
++ 
++ 	As software gets to the level of "huge", how would a redesign help
++ 	fight name collision problems?

If those subroutines are used outside of the package, they are clearly
part of the interface. If you get name collision in your interface,
you have designed your interface wrong.

Packages help you avoid name collision; but if you're making an interface
that has name collisions, you're on your own.


[Having said that, it would be nice if Exporter was a bit friendlier to
 module importing symbols, instead of having the exporting module
 define how the symbols will be named in the importing package.

 Exporter.pm should allow aliasing
 'Exporting_package::symbol_choosen_by_exporter' to
 'Importing_package::symbol_choosen_by_importer' instead of aliasing to
 'Importing_package::symbol_choosen_by_exporter'. ]



Abigail
-- 
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))


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

Date: Wed, 07 Oct 1998 21:37:17 -0400
From: Peter Smith <psmith01@mindspring.com>
Subject: strange problem with shift()...
Message-Id: <361C174D.AE81115A@mindspring.com>

I wrote a small script to read-in a fixed-length text file and spit out
to STDOUT only unique records - records are newline delimited.  Each new
line is 'push()'ed into an output array.  Problem is, whenever I push a
'\n' with the 'list' I'm pushing, my output gets completely whacked -
spitting out everything it reads.

In short:
1. Using 'push(@myarray, $somevalue)' works.
2. Using 'push(@myarray, "$somevalue")' works.
3. Using 'push(@myarray, "$somevalue\n")' does not work.

What don't I understand about push()??  Perl??

My code below.  It reads a text file (full of records) from STDIN,
checks to see if each already exists in the output @array, and if not
'push'es each in, and prints each out at the end.

-- 
--Peter--
psmith01@mindspring.com


#### BEGIN PROGRAM ####

#Create array
@Array = ();

#Read each line/record
while($line = <STDIN>) {
  #Chop-off newline for output brevity sake
  chop($line) if $line =~ /\n$/;

  #Set 'duplicate' marker -> returns true or false
  $match = &isMatch($line);

  #If not already in @Array, then add it
  if($match eq "false")
  {
    push(@Array,"$line");  	#Produces good output
    #push(@Array,"$line\n");    #Produces bad output
  }
}

#Print out unique records
&printRecords();


############################################
# SUBROUTINES
############################################
sub printRecords()
{
  foreach (@Array) 
  {
    print STDOUT "$_";
  }
}

#This subroutine looks at the global @Array
sub isMatch()
{
  #Pass-in record just read from STDIN
  local($var) = shift;

  foreach $line (@Array) 
  {
    if($line eq $var)
    { 
      return "true";
    }
  }
  return "false";
}  
#### END PROGRAM ####


#Here is the 'Good' output - all unique records:
12345

#Here is the 'Bad' output - not all unique records:
1
2
3
4
5
3
4
5
3
4
5

The input file looks exactly like the 'bad' output above...


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

Date: Wed, 7 Oct 1998 23:47:42 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: strange problem with shift()...
Message-Id: <1dgjyjd.923zva6j5yi3N@bay1-248.quincy.ziplink.net>

Peter Smith <psmith01@mindspring.com> wrote:

> #Read each line/record
> while($line = <STDIN>) {
>   #Chop-off newline for output brevity sake
>   chop($line) if $line =~ /\n$/;
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Newline removed...

>   #Set 'duplicate' marker -> returns true or false
>   $match = &isMatch($line);
    ^^^^^^^^^^^^^^^^^^^^^^^^^

Check without newline...

> 
>   #If not already in @Array, then add it
>   if($match eq "false")
>   {
>     push(@Array,"$line");   #Produces good output
>     #push(@Array,"$line\n");    #Produces bad output
      ^^^^^^^^^^^^^^^^^^^^^^^^

Add to array with newline...

>   }
> }

> sub isMatch()
> {
>   #Pass-in record just read from STDIN
>   local($var) = shift;
> 
>   foreach $line (@Array) 
>   {
>     if($line eq $var)
      ^^^^^^^^^^^^^^^^^

Compare chopped string to string with newline added!

>     { 
>       return "true";
>     }
>   }
>   return "false";
> }  

You're comparing strings *with* newlines to strings *without* newlines.
Thus, you're never going to get a match.



I'm afraid that your program is about as non-Perlish as you could get.
Here is the program again, as a Perl programmer might write it:

#### BEGIN PROGRAM ####

while(defined($line = <STDIN>)) {
  push(@Array, $line)
    if (not $seen{$line}++);

    # use a hash to keep track of which lines have been seen before
}

print @Array;

#### END PROGRAM ####


A few notes:


Don't use the strings "true" and "false" to denote true and false
values.  The false values are 0, '0', '', and undef; anything else is
true.  (Note that the string "false" is true when evaluated in a boolean
context.)

For example:

sub check_something {
  foreach $thing (@things) {
    return 1 if (&something($thing));
  }
  return 0;
}

if (&check_something) {
  print "something is true\n";
} else {
  print "something is false\n";
}



If you want to print all the elements of an array, just print the array:

print @Array;

It's not necessary to use a subroutine, nor to print the elements one at
a time.



Perl5 has the function chomp().  chomp() is like chop(), except it
removes the last character *only if it is a newline*.  So your line:
  chop($line) if $line =~ /\n$/;
could be replaced with:
  chomp($line);

(chomp() actually removes the value of $/ from the end of the string;
the default value of $/ is a newline.  Refer to perlfunc and perlvar for
more info.)



When you are referring to a single variable, putting it within quotes is
unnecessary.  Instead of:
  print STDOUT "$_";
you should simply write:
  print STDOUT $_;



Hope that helps!
  

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Wed, 7 Oct 1998 21:43:48 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Using Split and Join
Message-Id: <1dgjt9c.blh55v1bhd4rvN@bay1-244.quincy.ziplink.net>

[posted and mailed]

<cacharbe@my-dejanews.com> wrote:

> while (<TESTRUN>){
> 
>   if ($_ == /^\s.+/){
           ^^

Now that can't be right...

if ($_ =~ /^\s.+/)

> ##find the blank lines so I can keep formatting as close
> ##as possible to text file

The above does not match blank lines.  It matches lines beginning with a
single whitespace character.

/^\s+$/

> 
>    print OUT "<br>";
>   }else {
>     foreach $word (split){ ###Break the line apart

Splitting to @_ is deprecated.  Don't do it anymore.

@words = split;

>      if ($word =~ /(<A.*)/){###be careful of any formatting already there

You don't need to match .*, since it is guaranteed to match anyway, and
you don't do anything with the result.

You don't use $1 anywhere, so you don't need the parens.

>           }elsif ($word =~ /(http:.*)/) {

Same here.

>                 $word =  "<A href=$url>$url</A>";  ### reformat and shove back
>                                                    ### into string

1. You should put quotes around the URL.  You'd better hope all the URLs
are delimited with whitespace.

> ##   $_ = $word;    <---- Trouble Spot      ##Line where confusion
>                                                 ##really sets in - if I use
>                   ##html is kept, but first
>                                                 ##url is lost and  if I don't
>           }         ###html is lost....

I don't follow the cryptic comments here, but I'm guessing the problem
is actually caused by all the bugs elsewhere in the program.

>         }
>         join $_,@_;       ###Put it all back together

You're joining and discarding the result?  Perhaps you meant

$_ = join '', @words;

(@words used as per above.)

>   }
>          print OUT "$_";  ##And out to the file she goes

Because you discard the results of the join, $_ is unchanged from its
original value.

> }
> 
> Erg, please help if you can, or point me at the right resource.  I've read
> the Faq, perlfunc, win32 and referenced 3 O'Reilly books, but maybe I'm just
> missing something simple.  I am new at this.

Make sure you're following the proper syntax for all the builtin
functions you use.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Thu, 08 Oct 1998 00:56:56 GMT
From: tekkin@hotmail.com (Ken Williams)
Subject: What perl modules do I have???????
Message-Id: <361c0e22.0@news.cgocable.net>

How do I find out what perl modules I have installed?  Is there a switch or 
something?  perl -v just tells me the version number.  I running 5.004 on 
Linux 2.0.35.

Thanks.


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

Date: 12 Jul 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 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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