[22343] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4564 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 13 18:05:53 2003

Date: Thu, 13 Feb 2003 15:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 13 Feb 2003     Volume: 10 Number: 4564

Today's topics:
    Re: Accessing a remote DB <tore@aursand.no>
    Re: Accessing files in html folder from cgi script <tore@aursand.no>
    Re: amateur needs pattern matching example <tore@aursand.no>
    Re: binary data and utf8 (I think) <goldbb2@earthlink.net>
        dead children after forking from a remote shell (bplegend@yahoo.com)
    Re: dead children after forking from a remote shell <goldbb2@earthlink.net>
        error in comparing user supplied data to database <urzaserra@home.com>
    Re: Get vs. Post to Perl <tore@aursand.no>
    Re: grep with line number ? <mthunter@students.uiuc.edu>
    Re: grep with line number ? (Anno Siegel)
        Hiding user input (e.g. passwords) <rhughes@ant.hiwaay.net>
    Re: Hiding user input (e.g. passwords) <shondell@cis.ohio-state.edu>
        How to report progress on command line (Seth Brundle)
    Re: How to report progress on command line <shondell@cis.ohio-state.edu>
    Re: How to report progress on command line <goldbb2@earthlink.net>
        Passing Hard Referance down more than one Sub <thomasb95@mac.com>
    Re: Passing Hard Referance down more than one Sub <mjcarman@mchsi.com>
    Re: Passing Hard Referance down more than one Sub (Jay Tilton)
    Re: Perl+Tk+MySQL for Win32 that *works*? (Randy Kobes)
    Re: Please explain this weird error message <tore@aursand.no>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 13 Feb 2003 20:44:56 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Accessing a remote DB
Message-Id: <pan.2003.02.13.07.27.25.791868@aursand.no>

On Wed, 12 Feb 2003 16:18:49 -0800, Robert F. wrote:
> We are using Perl on a web server running Win 2000 Server and
> it is connected to an Alpha Server running OpenVMS as a file
> server.  Is there some way that I can access data from a
> database on the Alpha Server?

Yes, unless there is some obscure SQL server running on the Alpha Server
for which there aren't any DBI drivers. :-)

If, say, the Alpha Server runs MySQL, you should be able to connect to it
like this;

  #!/usr/bin/perl
  #
  use strict;
  use warnings;
  use DBI;

  .
  .
  .

  my $dbh = DBI->connect("DBI:mysql:database=db;host=alpha;port=3306",
                         "username, "password");

Install the DBI module (from CPAN, http://www.cpan.org/) and read its
documentation ('perldoc dbi').

BTW: The port used above (3306) is the default MySQL port.  It's your
responsibility to make sure that the parameters sent to connect() are
correct, of course.


-- 
Tore Aursand - tore@aursand.no - http://www.aursand.no/


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

Date: Thu, 13 Feb 2003 20:44:56 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Accessing files in html folder from cgi script
Message-Id: <pan.2003.02.13.19.39.09.398615@aursand.no>

On Thu, 13 Feb 2003 00:29:24 -0800, Craig wrote:
> $msg = MIME::Lite->new(
>              From     =>'me@myhost.com',
>              To       =>'craigdessoy@hotmail.com',
>              Cc       =>'blah@blahblah.com',
>              Subject  =>Tesing testing',

Typo.

>              Path     =>'var/www/html/despatches.csv'

And you are _sure_ that this path exists _relative_ to where your script
is being executed?  I don't think so.  Instead, try to use an absolute
path to your file;

  Path => '/var/www/html/despatches.csv'

Good luck!


-- 
Tore Aursand - tore@aursand.no - http://www.aursand.no/


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

Date: Thu, 13 Feb 2003 20:44:35 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: amateur needs pattern matching example
Message-Id: <pan.2003.02.12.14.56.31.202318@aursand.no>

On Wed, 12 Feb 2003 05:40:51 -0800, Mooky Mooksgill wrote:
> I'd like to parse certain values out of an HTML file [...]

Ooooh!  That _is_ really rocket science, believe it or not!  Parsing HTML
is actually very difficult when you think of all the non-standard HTML
code on the web today.

However, there are modules which comes to rescue;  Download HTML::Parser
from CPAN (www.cpan.org).  It's a very handy module.

> <font face="verdana" size="1" color="#333366"><b>8:25
> AM</b>&nbsp;</font></td>
> 
> I'd like just the '8:25 AM'
> 
> and put in to a file bar.inc as:
> 
> <td class=time>8:25 AM</td>

On the other hand;  If you _know_ what the HTML you're gonna parse look
like, you can do this the old-fashioned way (untested);

  $html =~ m,<b>(\d+:\d+ \w{2})</b>,m;
  $time =  $1; # Should be '8:25 AM' now

More information about regular expressions;

  'perldoc perlre'
  'perldoc perlretut'


-- 
Tore Aursand - tore@aursand.no - http://www.aursand.no/


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

Date: Thu, 13 Feb 2003 13:18:56 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: binary data and utf8 (I think)
Message-Id: <3E4BE190.66C4CB1A@earthlink.net>

Michael Lapsley wrote:
[snip]
> Finding the problem was very dificult since length($scalar)
> incorrectly reported the string as being the true length minus the
> extra characters.

Actually, it would be more correct to say that length($scalar) correctly
reported the length of the string in *characters*, but this length was
*not* correct with respect to the number of *bytes*.

> Eventually I got into the ball park by doing @x=split('',$scalar)  p
> $x[0] in the debugger, and this generated an error referring to utf8.

Hmm... sounds like you ran into one of the bugs in utf8 handling in
perl5.6.1.   If you were to upgrade to 5.8.0, it's quite possible that
the problem would go away entirely.

> Otherwise I had no way of telling that utf8 was implicated, and the
> documentation is simply too large if you do not know where to start.

IIRC from your description, the problem was that "\x{ hex chars }"
always produces utf8, even when the value of that byte was <= 255.  I
believe that this is fixed in perl5.8.0.

> I think if a new version of perl is going to alter data silently there
> should be a warning with -w or diagnostics.

If you have warnings enabled, the most recent perl (called bleadperl,
which is 5.9) will emit a warning when you attempt to write a string
which has the utf8 flag set to a filehandle which expects bytes -- I'm
not sure whether 5.8.0 already does that, though probably it does.

> And anyway, defaulting to this behaviour unless you remember some
> obscure pragmas is not very confidence inspiring: are there other
> new 'gotchas' awaiting me?

Doubtless there are -- any gotchas which were known at the time that 5.8
was released were fixed in that version.  Any gotchas which were unknown
probably still exist.

The only "big" gotcha with 5.8.0, is that if you're writing binary data
to a filehandle, you *must* have previously called binmode() on that
handle, *even if* you're on unix.


-- 
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
 landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"


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

Date: 13 Feb 2003 12:21:10 -0800
From: bplegend@yahoo.com (bplegend@yahoo.com)
Subject: dead children after forking from a remote shell
Message-Id: <5d0822ae.0302131221.1513e5da@posting.google.com>

Hi perl gurus,

this script I wrote forks off N number of children and each child
sends an oracle file to a host. $cmd=q{dd if=/path/to/file | ssh -Ci
pphrase $host_b "dd of=/path/to/file"}:  We usually have like five to
ten files to send and we fork off three children at a time to send
each file.


I also had a while loop around the system() to check for the return
code to avoid the 'connection timed out' in $host_b. If the dd fails,
it would resend the file. The problem is when the connection timed
out, the children in $host_b are left without closing its connection.
I checked in $host_b and their parent is 'sshd'. However their parent
process in $host_a did exit correctly. ($host_a is the origin host and
$host_b is the destination host)

I looked at cpan.org and it mentioned something which I think it might
be the solution but I am not quite sure what they mean by 'reopen
those to /dev/null'.
Is it adding "open (STDIN,'</dev/null');" before the "sleep 10*$cnt"
in my code?

Could someone shed some lights on this for me please?

thanks,

benny

[cpan.org]
-- cut here ---
 ...
Note that if your forked child inherits system file descriptors like
STDIN
and STDOUT that are actually connected by a pipe or socket, even if
you
exit, then the remote server (such as, say, a CGI script or a
backgrounded
job launched from a remote shell) won't think you're done. You should
reopen those to /dev/null if it's any issue. 
 ...
--- cut here end ---


[my code]
--- cut here ---
######
#  Child process kicks off the job
#
sub child {
  my $cnt = 0;
  my $maxloop = 10;

  while ( $cnt++ < $maxloop ) {
    $ret_ddcmd = system @_;
    if ( $ret_ddcmd ) {
      logger " ::sleeping ",10*$cnt,"\n";
      sleep (10 * $cnt);
      $dd_status = $ret_ddcmd;
      logger " ::resuming\n";
    }  else {
      $dd_status = 0;
      last;
    }
  }
  return $dd_status
}


######
#  Fork a child and return the pid to the parent process.
#  The child process kicks off and execute
#
sub create_child {
  my $ret;
  my $pid = fork;
  sleep 1;
  return $pid if $pid;
  $ret=child @_;
  exit($ret);   # returns from $dd_status in child()
}


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

Date: Thu, 13 Feb 2003 17:06:31 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: dead children after forking from a remote shell
Message-Id: <3E4C16E7.ACA59C17@earthlink.net>

"bplegend@yahoo.com" wrote:
> 
> Hi perl gurus,
> 
> this script I wrote forks off N number of children and each child
> sends an oracle file to a host. $cmd=q{dd if=/path/to/file | ssh -Ci
> pphrase $host_b "dd of=/path/to/file"}:

The input part of this is a fairly useless use of "dd".

Consider doing:

 $cmd=q{ssh -Ci pphrase $host_b "dd of=/path/to/file" < /path/to/file}:

> We usually have like five to ten files to send and we fork off three
> children at a time to send each file.

Uh...  You mean that for each file, there are three children sending it
simultaneously?  That sounds bizzarre.

Unless you meant, there are three children active at any one time, and
as each one finishes, you start the next one, with the next file, which
makes rather mroe sense.

> I also had a while loop around the system() to check for the return
> code to avoid the 'connection timed out' in $host_b.

Precisely how do you find out that 'connection timed out' is the
particular error?

> If the dd fails, it would resend the file.

The 'dd' is doing nothing but reading from the file, and sending it to
it's stdout.  It's the ssh program which is doing the actual transmision
of the file.

> The problem is when the connection timed out, the children in $host_b
> are left without closing its connection.
> I checked in $host_b and their parent is 'sshd'. However their parent
> process in $host_a did exit correctly. ($host_a is the origin host and
> $host_b is the destination host)

This explanation sounds a bit odd.  *Which* processes living on $host_b
are still alive?  *Which* processes on $host_a exited correctly?

On the sending end:  Since you're using system STRING, the shell is
being invoked -- is it the shell which has exited properly, or ssh which
has exited properly, or dd which has exited properly, or is it the perl
process which you fork()ed which exited properly?

On the recieving end:  I assume that the process which is still alive is
the 'dd of=...'.  Am I assuming correctly?

[snip code]

Try something like this:

my @files = (
   ["/path/to/hosta_file", "hostb", "/path/to/hostb_file"],
   ["/path/to/hosta_file", "hostb", "/path/to/hostb_file"],
);
my %processes;
while( 1 ) {
   while( keys(%processes) >= (@files ? 3 : 1) ) {
      my $pid = wait or die;
      my $command = delete $processes{$pid} or die;
      my $tries = ++$command->[3];
      next if $? == 0 or $tries > 10;
      push @files, $command;
   }
   my $command = shift @files or last;
   defined($pid = fork) or die;
   if( $pid ) {
      $processes{$pid} = $command;
      next;
   }
   my ($ifile, $hostb, $ofile) = @$command;
   open( STDIN, "<", $ifile ) or die;
   open( STDOUT, ">", "/dev/null" ) or die;
   exec "ssh", "-Ci", "pphrase", $hostb, "dd of=$ofile";
   exit 1;
}

[untested]

-- 
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
 landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"


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

Date: Thu, 13 Feb 2003 21:37:14 GMT
From: "matt" <urzaserra@home.com>
Subject: error in comparing user supplied data to database
Message-Id: <eeU2a.805$QU2.50987@news2.west.cox.net>

Hi,



This is part of an email list signup script I purchased directly from the
author who also installed it onto my host's server. Since he installed it
and has been paid, he no longer responds to my emails to him about a defect
I found in the script. The problem is that although the script works, no
more than one person should be able to signup using a particular "USERID"
but unfortunately any numbers of people can signup using the same "USERID".
Per line 36, there is this statement:



if ($d_userid ne "") { $message .= "The 'User ID' you have chosen is already
on our database.<br>\n"; $found_err++; }



Apparently the author did try to write the code to compare the inputted
value "USERID" to the contents of mySQL database. I am assuming that if
there was a duplicate the user would be asked to try again. Please note the
other checks for duplications such as line 43 and line 51 perform correctly:



if ($ccontact ne "") { $message .= "The 'Contact Email' you have entered is
already on our database.<br>\n"; $found_err++; }



if ($ccontact ne "") { $message .= "The 'Subscribed Email' you have entered
is already on our database.<br>\n"; $found_err++; }



So that if the "Contact Email" or the "Subscribed Email" preexists in the
mySQL database the user would be asked to supply a different email address
for each of these values. These two lines (43 and 51) works as they should.
This is not the case for the "USERID" though.



The script you see here is the complete signup.cgi script. Since I am not a
programmer, I would very much appreciate any ideas as to what's wrong and if
there is an easy fix. Any help or comments would be very much appreciated.

#!/usr/bin/perl

use CGI::Carp qw(fatalsToBrowser);
require "user-lst.inc";

$| = 1;
print "Content-type: text/html\n"; # Header Left Open here knowingly

use CGI;
$in = new CGI;
$action = $in->param('action');
$new_userid = $in->param('new_userid');
$new_password = $in->param('new_password');
$new_passwordv = $in->param('new_passwordv');
$new_fullname = $in->param('new_fullname');
$new_contact = $in->param('new_contact');
$new_subscribed = $in->param('new_subscribed');
$mtY = $in->param('mtY');
if ($mtY eq "") { $mtY = "FREE"; }
elsif (($mtY ne "FREE")&&($mtY ne "PRO")&&($mtY ne "PLATINUM")) { $mtY =
"FREE"; }

if ($new_userid eq "") { $message .= "The field 'User ID' must be filled in
 ...<br>\n"; $found_err = "9"; }
if ($new_password eq "") { $message .= "The field 'Password' must be filled
in ...<br>\n"; $found_err = "9"; }
if ($new_passwordv ne "$new_password") { $message .= "The passwords entered
do not match ...<br>\n"; $found_err = "9"; }
if ($new_fullname eq "") { $message .= "The field 'Full Name' must be filled
in ...<br>\n"; $found_err = "9"; }
if ($new_contact eq "") { $message .= "The field 'Contact Email' must be
filled in ...<br>\n"; $found_err = "9"; }
if (($new_subscribed eq "")&&($mtY ne "PLATINUM")) { $message .= "The field
'Subscribed Email' must be filled in ...<br>\n"; $found_err = "9"; }
if ($found_err eq "9") { &PrintError($message); exit; }

&OpenMySQL;
$found_err = 0;
$dtable = "$prefix"."_members";
$m_type = "$mtY";
&DoConv;
&GetMemberInfo($new_userid);
if ($d_userid ne "") { $message .= "The 'User ID' you have chosen is already
on our database.<br>\n"; $found_err++; }

$mysql = "SELECT * FROM $dtable WHERE contact='$new_contact'";
$results = $dbh->prepare($mysql);
$results->execute();
$ref = $results->fetchrow_hashref();
$ccontact = $ref->{'contact'};
if ($ccontact ne "") { $message .= "The 'Contact Email' you have entered is
already on our database.<br>\n"; $found_err++; }

if ($new_contact ne "$new_subscribed") {
  $mysql = "SELECT * FROM $dtable WHERE subscribed='$new_subscribed'";
  $results = $dbh->prepare($mysql);
  $results->execute();
  $ref = $results->fetchrow_hashref();
  $ccontact = $ref->{'contact'};
  if ($ccontact ne "") { $message .= "The 'Subscribed Email' you have
entered is already on our database.<br>\n"; $found_err++; }
  }

$mysql = "SELECT * FROM $dtable WHERE subscribed='$new_contact'";
$results = $dbh->prepare($mysql);
$results->execute();
$ref = $results->fetchrow_hashref();
$ccontact = $ref->{'subscribe'};
if ($ccontact ne "") { $message .= "The 'Contact Email' you have entered is
already on our database.<br>\n"; $found_err++; }

if ($new_contact ne "$new_subscribed") {
  $mysql = "SELECT * FROM $dtable WHERE contact='$new_subscribed'";
  $results = $dbh->prepare($mysql);
  $results->execute();
  $ref = $results->fetchrow_hashref();
  $ccontact = $ref->{'subscribe'};
  if ($ccontact ne "") { $message .= "The 'Subscribed Email' you have
entered is already on our database.<br>\n"; $found_err++; }
  }
if ($found_err >= 1) { &CloseMySQL; &PrintError($message); exit; }

if ((($mtY eq "PRO")or($mtY eq "PLATINUM"))&&($safelist_type eq "NORMAL")) {
  require "$data_dir/AffPayOut.pm";
  &PayOutNow; }
if (($mtY ne "")&&($safelist_type eq "POINTS")) {
  require "$data_dir/AffPayOut.pm";
  &PayOutNow; }

if ($mtY eq "PLATINUM") { $dstatus = "VERIFIED"; $status_note = "You can now
login and send your ad to the entire list."; $acode = ""; }
else {
  $dstatus = "UNVERIFIED";
  $status_note = "You must verify your subsribed email address by clicking
on the link sent there ($new_subscribed) before you are able to send your
ads to the list.";
  ($ab,$cd,$ef,$gh) = split(/\./, $ipadd);
  $acode = ((($ab + $ef)*$cd)-$gb)*$sec;
  open (MAIL, "|$mailprog -t");
  print MAIL "To: $fullname <$new_subscribed>\n";
  print MAIL "From: $site_name <$admin_email>\n";
  print MAIL "Subject: Account Activation Link.\n\n";
  print MAIL "In order to activate your $site_name $mtY account just click
on the link below:\n\n";
  print MAIL "$cgi_bin/verify.cgi?$acode \n";
  print MAIL "<a href=\"$cgi_bin/verify.cgi?$acode\">Click here to
re-activate</a> \n\n";
  print MAIL "$site_name\nAdministration\n";
  close (MAIL); }

open (MAIL, "|$mailprog -t");
print MAIL "To: $fullname <$new_subscribed>\n";
print MAIL "From: $site_name <$admin_email>\n";
print MAIL "Subject: Your New $mtY Safelist Account.\n\n";
print MAIL "Hi $new_fullname\n\n";
if ($mtY ne "FREE") { print MAIL "Thank you for your order.\n\n"; }
print MAIL "Your new safelist account at the $site_name was\n";
print MAIL "successfully created.\n\n";
print MAIL "Below is your login information along with the login url:\n\n";
print MAIL "Login URL:\n";
print MAIL "$login_url\n\n";
print MAIL "User ID: $new_userid\n";
print MAIL "Password: $new_password\n\n";
print MAIL "Save and/or Print this email for your records.\n\n\n";
print MAIL "$admin_name\n";
print MAIL "Webmaster\n";
print MAIL "$site_name\n";
close (MAIL);

if ($notify_paid eq "ON") {
  open (MAIL, "|$mailprog -t");
  print MAIL "To: $admin_name <$admin_email>\n";
  print MAIL "From: $site_name <$bounced_email>\n";
  print MAIL "Subject: New \"Paid\" Member Notification\n\n";
  print MAIL "New $mtY Member Information:\n\n";
  print MAIL "User ID: $new_userid\n";
  print MAIL "Subscribed Email: $new_subscribed\n";
  print MAIL "Contact Email: $new_contact\n";
  print MAIL "IP Address: $ENV{'REMOTE_ADDR'}\n";
  print MAIL "Name: $new_fullname\n";
  print MAIL "Type: $mtY\n\n";
  print MAIL "For more information on this member visit your Administrative
Section.";
  close (MAIL); }

$dtable = "$prefix"."_members";
$sql = "INSERT INTO $dtable (userid, password, fullname, contact,
subscribed, type, joindate, ipaddress, status, vacation, bounces, points,
notes, extra1, extra2, extra3) VALUES
('$new_userid','$new_password','$new_fullname','$new_contact','$new_subscrib
ed','$mtY','$todays_date','$ipadd','$dstatus','OFF|','0','$points_join','','
$acode','','')";
$dbh->do($sql);
$dtable = "$prefix"."_alinks";
$sql = "INSERT INTO $dtable (userid, linkssent, clicks, earnings,
paidearnings, resetdate, extra1, extra2, extra3) VALUES
('$new_userid','0','0','0','0','$todays_date','','','')";
$dbh->do($sql);
$dtable = "$prefix"."_affiliates";
$sql = "INSERT INTO $dtable (userid, clicks, referrals, earnings,
paidearnings, resetdate, extra1, extra2, extra3) VALUES
('$new_userid','0','0','0','0','$todays_date','','','')";
$dbh->do($sql);
&CloseMySQL;

open (NEWCFILE, ">$data_dir/codes/$new_userid.idb");
print NEWCFILE "";
close (NEWCFILE);
if ($opsystem eq "UNIX") { $mde = 0777; chmod ($mde,
"$data_dir/codes/$new_userid.idb"); }
open (NEWAFILE, ">$data_dir/alinks/$new_userid.idb");
print NEWAFILE "";
close (NEWAFILE);
if ($opsystem eq "UNIX") { $mde = 0777; chmod ($mde,
"$data_dir/alinks/$new_userid.idb"); }

print "\n";
$section = "New Member Signup - Account Created";
require "$data_dir/html_head.inc";
print <<ACCOUNTMADE;
<div align="center">
<p><b>Your $mtY account has been created successfully.</b></p>
<p>$status_note</p>
<p>Your login information has been sent to your contact email address
($new_contact).</p>
<p>Click on the button below to Login automatically to the members section
with your new account.</p>
<form method="POST" action="$cgi_bin/login.cgi"><p><input type="submit"
value="Login ($new_userid)" class="form-button"></p><input type="hidden"
name="userid" value="$new_userid"><input type="hidden" name="password"
value="$new_password"></form>
</div>
ACCOUNTMADE
require "$data_dir/html_foot.inc";
exit;





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

Date: Thu, 13 Feb 2003 20:44:29 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Get vs. Post to Perl
Message-Id: <pan.2003.02.11.00.55.01.205789@aursand.no>

On Mon, 10 Feb 2003 15:02:44 -0800, Jack Cane wrote:
>> This smells like you're doing your own form parameters parsing. Don't.
>> GET vs. POST shouldn't make a difference.

> Not sure what you mean.
> [...]

He means that you shouldn't try to parse the form parameters yourself, but
let the CGI module take care of that for you.  Example;

  #!/usr/bin/perl
  #
  use strict;
  use warnings;
  use CGI qw(:cgi); # We only need the CGI part

  my $cgi = CGI->new();

  my $row1 = $cgi->param( 'ROWSTART' );
  my $row2 = $cgi->param( 'ROWEND' );

  my $query1 = 'SELECT LastName, FirstName, MidInitial, Username
                FROM MemberNames
                WHERE MbrNr > ? AND MbrNr < ?';
  my $sth = $dbh->prepare( $query1 );
  $sth->execute( $row1, $row2 );
  # Grab your data here
  $sth->finish();

 ...or something like that.  I don't know what your script looks like, but
I assume you get the point.


--
Tore Aursand - tore@aursand.no - http://www.aursand.no/


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

Date: Thu, 13 Feb 2003 17:24:20 GMT
From: Mike Hunter <mthunter@students.uiuc.edu>
Subject: Re: grep with line number ?
Message-Id: <slrnb4nlbq.rdg.mthunter@ux12.cso.uiuc.edu>

On Thu, 13 Feb 2003 07:58:25 +0100, kamran wrote:
>  I am overwhelmed. This is the best newsgroup I have
>  ever visited. Everywhere else I am either met with silence
>  when displaying my lack of knowledge or told to go
>  read the FAQ or get myself a good book.

I'm rather surprised that wasn't the response here :)


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

Date: 13 Feb 2003 17:43:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: grep with line number ?
Message-Id: <b2glg9$l01$2@mamenchi.zrz.TU-Berlin.DE>

Mike Hunter  <mthunter@uiuc.edu> wrote in comp.lang.perl.misc:
> On Thu, 13 Feb 2003 07:58:25 +0100, kamran wrote:
> >  I am overwhelmed. This is the best newsgroup I have
> >  ever visited. Everywhere else I am either met with silence
> >  when displaying my lack of knowledge or told to go
> >  read the FAQ or get myself a good book.
> 
> I'm rather surprised that wasn't the response here :)

That's because "grep with line number" isn't a FAQ.  Simple enough?

Anno


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

Date: Thu, 13 Feb 2003 21:00:36 -0000
From: Ralph Hughes <rhughes@ant.hiwaay.net>
Subject: Hiding user input (e.g. passwords)
Message-Id: <v4o1rkf9f9qd37@corp.supernews.com>

Anyone have a quick way to hide user typing?  I need to hide the input
of a password in a simple Perl script that is connecting to a Db.  
Generally I might grab the user input with something like this :
     $somevar = <STDIN>;

In this case, however that would result in the password being echoed 
to the screen.

Any ideas? 

Thanks and Regards,

-----------------------------------------
Ralph Hughes
rhughes@anteon.com
rhughes@hiwaay.net


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

Date: 13 Feb 2003 16:02:50 -0500
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: Hiding user input (e.g. passwords)
Message-Id: <xcw8ywjsxl1.fsf@psi.cis.ohio-state.edu>

Ralph Hughes <rhughes@ant.hiwaay.net> writes:

> Anyone have a quick way to hide user typing?  I need to hide the input
> of a password in a simple Perl script that is connecting to a Db.  
> Generally I might grab the user input with something like this :
>      $somevar = <STDIN>;

This is a FAQ.

perldoc -q password

(use Term::Readkey)
-- 
Ryan Shondell <shondell@cis.ohio-state.edu>


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

Date: 13 Feb 2003 12:08:28 -0800
From: brundlefly76@hotmail.com (Seth Brundle)
Subject: How to report progress on command line
Message-Id: <53e2ec95.0302131208.5bcb8c10@posting.google.com>

Let's say you want to process a file with many lines, and its takes a
while and you would like to report status in realtime ala:

bash> Processing line #2,345,999...

Where this line is constantly updated on the same line of the display
without creating a newline - i.e. it appears as if only the number
itself is changing. Hope this makes sense...

How would one go about this?


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

Date: 13 Feb 2003 16:00:26 -0500
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: How to report progress on command line
Message-Id: <xcwd6lvsxp1.fsf@psi.cis.ohio-state.edu>

brundlefly76@hotmail.com (Seth Brundle) writes:

> Let's say you want to process a file with many lines, and its takes a
> while and you would like to report status in realtime ala:
> 
> bash> Processing line #2,345,999...
> 
> Where this line is constantly updated on the same line of the display
> without creating a newline - i.e. it appears as if only the number
> itself is changing. Hope this makes sense...
> 
> How would one go about this?

Well, there's probably a better way to do this, but here's an example
of something that seems to come close to what you want.

#!/usr/local/bin/perl

use warnings;
use strict;

$| = 1; #autoflush

print "Counting # ";
for (1..20) {
    sleep 1;  # just to slow things down so they can be seen
    print "\b" x length $_ - 1, $_;
}

__END__

This will print backspaces equal to the length of the last number
printed, and then print the current number. 
-- 
Ryan Shondell <shondell@cis.ohio-state.edu>


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

Date: Thu, 13 Feb 2003 16:32:45 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How to report progress on command line
Message-Id: <3E4C0EFD.9A595ED3@earthlink.net>

Seth Brundle wrote:
> 
> Let's say you want to process a file with many lines, and its takes a
> while and you would like to report status in realtime ala:
> 
> bash> Processing line #2,345,999...
> 
> Where this line is constantly updated on the same line of the display
> without creating a newline - i.e. it appears as if only the number
> itself is changing. Hope this makes sense...
> 
> How would one go about this?


   #!/usr/local/bin/perl
   use warnings;
   use strict;
   $| = 1;
   print "Processing # 1";
   for (2..20) {
      sleep 1; print "\r";
      sleep 1; print "Processing # $_";
   }
   print "\n";
   __END__

-- 
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
 landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"


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

Date: Thu, 13 Feb 2003 18:49:16 GMT
From: "Tom" <thomasb95@mac.com>
Subject: Passing Hard Referance down more than one Sub
Message-Id: <MMR2a.402$3l2.36628520@newssvr15.news.prodigy.com>

Sorry for such a basic question  but I have been trying to send a referance
to an array thru more than one subroutine and I am failing.
I use say i.e. $referance = \@array1 then call the first subroutine but when
the first subrountne calls the next and then say I do a
print "----> @$referance[0]\n\r";   I get   ---->    and no values from
inside the array. I Have also tried TypeGlob but it did not work ether but I
also don't think it was intened to do that anyway
So I guess my question is how do you pass and array down multi. subroutines
or global it.
Note here I do preload the array with values.

Thanks for any help I can get.
                 Tom




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

Date: Thu, 13 Feb 2003 14:13:56 -0600
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: Passing Hard Referance down more than one Sub
Message-Id: <b2gua5$ic12@onews.collins.rockwell.com>

On 2/13/2003 12:49 PM, Tom wrote:
> 
> I have been trying to send a referance to an array thru more than one
> subroutine and I am failing.

Next time please show us the actual code you tried, tell us what
happened and what you expected to happen. Doing this allows us to tell
you where you went wrong. In the absence of that, the best I can offer
is a trivial example:

#!/usr/bin/perl -w
use strict;

my @array = ('A' .. 'D');

foo(\@array);

sub foo {
    my $ref = shift;
    bar($ref);
}

sub bar {
    my $ref = shift;
    print $ref->[0], "\n";
}

__END__

See also 'perldoc perlreftut' and 'perldoc perlref'

-mjc



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

Date: Thu, 13 Feb 2003 22:52:02 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Passing Hard Referance down more than one Sub
Message-Id: <3e4c2178.17461847@news.erols.com>

"Tom" <thomasb95@mac.com> wrote:

: Sorry for such a basic question  but I have been trying to send a referance
: to an array thru more than one subroutine and I am failing.
: I use say i.e. $referance = \@array1 then call the first subroutine but when
: the first subrountne calls the next and then say I do a

[...]

Ugh.  Try explaining that again with some code.

Describing a program with a list of steps leaves too much to the
imagination of the reader.

A short (less than 30 lines) complete program (from shebang to
__END__) that exhibits the problem will explain it better than words
ever could.



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

Date: 13 Feb 2003 19:40:45 GMT
From: randy@theoryx5.uwinnipeg.ca (Randy Kobes)
Subject: Re: Perl+Tk+MySQL for Win32 that *works*?
Message-Id: <slrnb4nsot.qpm.randy@theoryx5.uwinnipeg.ca>

On Thu, 13 Feb 2003 04:38:06 -0000, Jim Seymour <gort@LinxNet.com> wrote:
>In article <uHD2a.42007$7_.180167@news1.mts.net>,
>	"Randy Kobes" <randy@theoryx5.uwinnipeg.ca> writes:
>[snip]
>> Aahh ... I was assuming a local database - sorry about that.
>
>No way for you to know.  One could as well argue your mention of a
>libmySQL.dll that I never saw should have clued *me* in.  But I never
>gave a thought to the fact that the DBD::mysql package depended on
>libraries that weren't there! It just so-happens that every system
>I've played with Perl/MySQL on *happened* to either have MySQL
>installed upon it or was a system that had access to the requisite
>libraries via NFS.
>
>I *am* kind of surprised this is the first time this has come up,
>though.  I would have thought what I'm trying to do and the way I'm
>trying to use the package would be relatively common?

I'm surprised too this hasn't arisen before. It may be because 
most people happen to have a local mysql installation already, 
or else didn't realize that remote connections are possible,
and so never tried.

>>                                                              Under
>> ftp://theoryx5.uwinnipeg.ca/pub/other/  I just put a copy of
>> libmySQL.dll from a mysql 3.xx installation - try placing that
>> under C:\Perl\site\lib\auto\DBD\mysql\ (where the Perl
>> mysql.dll library is) and see if that works.
>
>That did it, Randy!  Thanks!
>
>> I thought about including this in the DBD::mysql package,
>> but I don't like to include dlls for which a user may have
>> another copy or version. I'll look into trying to include
>> it in an interactive post-install script.
>
>Just throwing a thought out...
>
>Obviously I don't know PPM well.  (Hardly at all.)  But does it
>support enforcing dependencies?  RPM, as you're probably aware, will
>refuse to install things if there are missing dependencies.  So will
>Sun's package manager.  So do all of the Perl source packages I've
>installed under *nix.  Leads to "recursive" install hell sometimes,
>but better than what's happened to me lately, perhaps.  If so, I'm
>wondering if it wouldn't make sense to make libmySQL a separate PPM
>package and make the others dependent on it?

PPM does have a concept of dependencies on other ppm packages,
as specified in the ppd file. Thus, for example, DBD-mysql
depends on DBI, so when you install DBD-mysql, it'll also
install DBI if you don't already have it. For needed external 
libraries and such this won't work in the same manner, though -
ppm installs things into the local Perl tree. Rather, what one 
could do is specify in the ppd file a post-install script 
that ppm will run after installation on the Perl side is complete
(although this strictly isn't the right thing to do for 
dependencies - it should be a "pre-install" script). The syntax 
of these scripts changed a bit with newer ppm utilities, but I've 
now added such a script to our DBD-mysql package that will offer,
if the user wants, to fetch and install libmySQL.dll.

Thanks for persisting in this - hopefully this post-install
script will help future users avoid the difficullties you
had ...

-- 
best regards,
randy


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

Date: Thu, 13 Feb 2003 20:44:41 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Please explain this weird error message
Message-Id: <pan.2003.02.12.20.54.43.119930@aursand.no>

On Wed, 12 Feb 2003 15:00:09 -0500, Luis Fernandes wrote:
> $prfile=~s/*.ps/PostScript File/;
> 
> When run, I get the error: "Quantifier follows nothing before HERE mark in
> regex m/* << HERE .ps/ at ttt line 3."

Both '*' and '.' are special characters in regular expressions;

  '*' matches 0, 1 or more
  '.' matches any character (except newline)

Thus, for these characters to be used in a "normal" way, you have to
escape them by putting a '\' in front of them;

  m/\*\.ps/;

In your example, however, I don't think that'll help you much.  It seems
like you're trying to match files by their extension.  If so, you should
check what the extension's like (untested);

  my %filetypes = (
      'ps'  => 'Postscript',
      'gz'  => 'Compressed (GZ)',
      'zip' => 'Compressed (ZIP)',
      'exe' => 'Executable',
  );

  $prfile =~ s/\.(.*)$/$filetypes{$1}/;


-- 
Tore Aursand - tore@aursand.no - http://www.aursand.no/


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 4564
***************************************


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