[19263] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1458 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 7 21:10:36 2001

Date: Tue, 7 Aug 2001 18:10:16 -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: <997233016-v10-i1458@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 7 Aug 2001     Volume: 10 Number: 1458

Today's topics:
    Re: SQL error with s/// <l_pantin@hotmail.com>
    Re: SQL error with s/// <bwalton@rochester.rr.com>
    Re: String version of += assignment operator?? (Damian James)
    Re: String version of += assignment operator?? (Tad McClellan)
    Re: System Call Question <cberry@cinenet.net>
    Re: System Call Question <andrew.savige@ir.com>
    Re: System Call Question (Tad McClellan)
    Re: System Call Question (Charles DeRykus)
    Re: System Call Question <dbe@wgn.net>
        Win9.x / Win.me Memory Monitor Via Perl <godzilla@stomp.stomp.tokyo>
    Re: Win9.x / Win.me Memory Monitor Via Perl <godzilla@stomp.stomp.tokyo>
    Re: Win9.x / Win.me Memory Monitor Via Perl <cberry@cinenet.net>
    Re: Win9.x / Win.me Memory Monitor Via Perl <godzilla@stomp.stomp.tokyo>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 08 Aug 2001 00:23:33 GMT
From: "Kevin Bartz" <l_pantin@hotmail.com>
Subject: Re: SQL error with s///
Message-Id: <9E%b7.7004$1p1.561299@bgtnsc04-news.ops.worldnet.att.net>

You're matching the sequence \'\", not each of those characters
individually.

One option is to replace both your lines with $form{$each_var} =~
s/['"]/'/g;

Kevin

Daniel Gibby wrote in message
<_M_b7.176$Ki1.9121@bgtnsc06-news.ops.worldnet.att.net>...
:I am trying to use the s/// modifier to replace any single quotes or
double
:quotes with a backslash+quote so that I can insert the quote into my
SQL
:database.
:
:This is how I am doing it:
:
:    $single_quote = "\\'";
:    $form{$each_var} =~ s/\'\"/$single_quote/g;
:
:For some reason it doesn't seem to be working correctly. Am I missing
:something?
:
:




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

Date: Wed, 08 Aug 2001 00:47:05 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: SQL error with s///
Message-Id: <3B708C53.41A19084@rochester.rr.com>

Daniel Gibby wrote:
> 
> I am trying to use the s/// modifier to replace any single quotes or double
> quotes with a backslash+quote so that I can insert the quote into my SQL
> database.
> 
> This is how I am doing it:
> 
>     $single_quote = "\\'";
>     $form{$each_var} =~ s/\'\"/$single_quote/g;
> 
> For some reason it doesn't seem to be working correctly. Am I missing
> something?

Doesn't seem to be working correctly?  Well, exactly what is it doing or
not doing?  Generating a kernel panic?  Nothing?  An error message (if
so, what does it say)?  What?  Are you quoting SQL variable names? 
String literals?  Dates?  Times?  Usually SQL does not use a \ to escape
characters, but rather uses the delimiter-doubling method.  So 

     'here''s an apostrophe:'''

would be SQLese for the string:

     here's an apostrophe:'

But you might need to look at the docs for your particular incarnation
of SQL.  Whatever you do, don't confuse Perl's delimiter-escaping
mechanisms with that of SQL.  They are different.

Regarding your example code, I have trouble understanding what you
expected it to do.  Escaping ' and " is not necessary in a regex or in a
plain replacement string (that is, not using the /e switch), and no SQL
I know of has any use for \' .  You might try DBI's quote() method,
which will just fix it up for you, doing the right thing for the
database with which it is being used.
-- 
Bob Walton


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

Date: 7 Aug 2001 22:39:03 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: String version of += assignment operator??
Message-Id: <slrn9n0res.r35.damian@puma.qimr.edu.au>

Carlos C. Gonzalez chose Tue, 07 Aug 2001 21:23:19 GMT to say this:
>In article <slrn9n0g80.ii3.tadmc@tadmc26.august.net>, Tad McClellan at 
>tadmc@augustmail.com says...
>
>> dot is the string concatenation operator:
>> 
>>    ${$string} .= 'See you tommorrow.';
>> ...
>>    perldoc perlop
>> 
>
>I will have to read the perlop Tad.  It's a hassle to use perldoc on 
>Windows.  It comes up in this archaic DOS window which scrolls off the 
>screen with every page and that I cannot readily page up on.  
>ActiveStates help is better but in order to find something like perlop I 
>have to manually scroll down this long HTML page before I get to it.
>...

If you are unhappy with ActiveState's doc layout, you might want to consider
generating your own docs using one of the handy 'podlators' that come with
perl. If you have a look for pod2* in whichever directory holds you perl
binaries, you'll get the idea. 

It's relatively easy to automate, so that you can keep a fully up-to-date
flat directory of perl docs in your format of choice, where you just run a
script to regenerate the dir whenever you install a module. Certainly this
is how I keep a full set of Perl docs on my Palm :-).

Another alternative would be to run cygwin with xfree86, then use xterm
windows instead of the native DOS windows, and whichever shell you prefer
to use instead of DOS :-).

Cheers,
Damian
-- 
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...


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

Date: Tue, 7 Aug 2001 18:27:04 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: String version of += assignment operator??
Message-Id: <slrn9n0qpo.kas.tadmc@tadmc26.august.net>

Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
>In article <slrn9n0g80.ii3.tadmc@tadmc26.august.net>, Tad McClellan at 
>tadmc@augustmail.com says...
>
>> dot is the string concatenation operator:
>> 
>>    ${$string} .= 'See you tommorrow.';
>> 
>
>Thanks Tad.  


Glad to help.


>> Maybe you should take a break from coding, and research what tools
>> Perl provides for you to use. Using the Right Tool For The Job
>> only once or twice will repay you for the time you spend reading:
>> 
>>    perldoc perlop
>> 
>
>I will have to read the perlop Tad.  It's a hassle to use perldoc on 
>Windows.  


It's a hassle to _program_ on Windows. No news there.


>I 
>have found that in general it is much faster for me to go to Google and 
>either search the old Deja News group postings and / or just look for 
>something like "Perl assignment operators".  Letting Google pull up 
>relevent content for me.  


If it isn't the standard Perl docs, it isn't Good Enough.

I want it from the horse's mouth (p5p).


>Unfortunately the content does not seem to be as thorough as perldoc 
>stuff.  


>I will have to figure out how to efficiently use perl.org's or 
>CPAN's perldoc I guess. 


Or even     www.perldoc.com   :-)


I _never_ actually use perldoc.

I find out where the *.pod files are on my system, and grep(1)
them to my heart's content.


>In all the searching and reading I did (including Learning Perl) I do not 
>recall seeing the .= operator once.  


Because you can combine _any_ operator with assignment. Since they
already list all of the operators, it would be redundant to also
list the assignment shortcut form.


>I spent quite a bit of time looking 
>through assignment operators.  I guess it is one of those operators that 
>is not mentioned much outside of perldoc.  


Yet another reason to make 'outside of the standard docs' a
second-level resource  :-)


>Thanks again Tad.  I will spend time later today or tommorrow boning up 
>on how to search through perldoc efficiently on perl.org or CPAN.


Do it on your very own hard disk instead.

Perl is free. Download and unpack it. Find the *.pod files.
Copy them to a safe place. Delete the distribution without
installing it.

Now you can see The Real Stuff, and search it in any manner you choose!


Get a listing of all of the FAQ questions for easy searching:

   grep "^=" perlfaq[1-9].pod >faq.heads

or on tools-challenged OSes:

   perl -ne "print if /^=/" perlfaq[1-9].pod >faq.heads



-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 07 Aug 2001 22:48:27 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: System Call Question
Message-Id: <Xns90F6A0CD59F91cberrycinenetnet1@207.126.101.92>

"Mark Riehl" <mark.riehl@agilecommunications.com> wrote in
news:vzZb7.503$Pz1.66571@typhoon1.gnilink.net: 

> All - I've got a Win2k box and I'd like to make a system call
> (ipconfig) and determine my own IP address (trying to debug an ISP
> issue with changing IP addresses).  Is there a way to redirect the
> results of the system call into an array (similar to an ARGV)?  This
> way, I could walk through the array and find out my IP address.  Or,
> would it be easier to redirect the results of a system call into a
> file, open the file, and find the IP address. 

To get the output of an external program, you want `` -- aka qx() -- not 
system().  See 'perldoc perlop' for details.

-- 
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake



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

Date: Wed, 8 Aug 2001 09:00:34 +1000
From: "Knob" <andrew.savige@ir.com>
Subject: Re: System Call Question
Message-Id: <mq_b7.7$%x2.619@news0.optus.net.au>


"Mark Riehl" <mark.riehl@agilecommunications.com> wrote in message
news:vzZb7.503$Pz1.66571@typhoon1.gnilink.net...
> All - I've got a Win2k box and I'd like to make a system call (ipconfig)
and
> determine my own IP address (trying to debug an ISP issue with changing IP
> addresses).  Is there a way to redirect the results of the system call
into
> an array (similar to an ARGV)?  This way, I could walk through the array
and
> find out my IP address.  Or, would it be easier to redirect the results of
a
> system call into a file, open the file, and find the IP address.
>
> Any suggestions?
>
> Thanks,
> Mark
>
>
If you just want to determine the ip address of a given machine,
you don't need to run the ipconfig command.
This Perl code will do it:
use Socket;
my $machine = 'put your machine name here';
print "machine='$machine'\n";
my $ipaddr = gethostbyname($machine);
if (defined($ipaddr))
{
   my $ip = Socket::inet_ntoa($ipaddr);
   print "ip='$ip'\n";
}





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

Date: Tue, 7 Aug 2001 18:31:41 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: System Call Question
Message-Id: <slrn9n0r2d.kas.tadmc@tadmc26.august.net>

Mark Riehl <mark.riehl@agilecommunications.com> wrote:

>Is there a way to redirect the results of the system call into
                                               ^^^^^^
>an array (similar to an ARGV)?

>Any suggestions?


Yes. Read the description for the functions that you use:

   perldoc -f system

      "This is I<not> what you want to use to capture the 
       output from a command, for that you should use..."


Do you sign contracts without reading them too?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 7 Aug 2001 23:39:31 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: System Call Question
Message-Id: <GHq1pv.445@news.boeing.com>

In article <vzZb7.503$Pz1.66571@typhoon1.gnilink.net>,
Mark Riehl <mark.riehl@agilecommunications.com> wrote:
>All - I've got a Win2k box and I'd like to make a system call (ipconfig) and
>determine my own IP address (trying to debug an ISP issue with changing IP
>addresses).  Is there a way to redirect the results of the system call into
>an array (similar to an ARGV)?  This way, I could walk through the array and
>find out my IP address.  Or, would it be easier to redirect the results of a
>system call into a file, open the file, and find the IP address.


perldoc -f qx  
perldoc perlop

my @ipconfig_out = qw{ C:/WINNT/system32/ipconfig.exe };
die $? if $?;


--
Charles DeRykus


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

Date: Tue, 07 Aug 2001 17:10:12 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: System Call Question
Message-Id: <3B708364.757E6D02@wgn.net>

Knob wrote:
> 
> "Mark Riehl" <mark.riehl@agilecommunications.com> wrote in message
> news:vzZb7.503$Pz1.66571@typhoon1.gnilink.net...
> > All - I've got a Win2k box and I'd like to make a system call (ipconfig)
> and
> > determine my own IP address (trying to debug an ISP issue with changing IP
> > addresses).  Is there a way to redirect the results of the system call
> into
> > an array (similar to an ARGV)?  This way, I could walk through the array
> and
> > find out my IP address.  Or, would it be easier to redirect the results of
> a
> > system call into a file, open the file, and find the IP address.
> >
> > Any suggestions?
> >
> > Thanks,
> > Mark
> >
> >
> If you just want to determine the ip address of a given machine,
> you don't need to run the ipconfig command.
> This Perl code will do it:
> use Socket;
> my $machine = 'put your machine name here';
> print "machine='$machine'\n";
> my $ipaddr = gethostbyname($machine);
> if (defined($ipaddr))
> {
>    my $ip = Socket::inet_ntoa($ipaddr);
>    print "ip='$ip'\n";
> }

This works good for me since the FAQ version fails for me:

	use strict;
	use Socket;

	my $host = (gethostbyname ("localhost"))[0];
	printf "hostname=$host; ";
	my $addr = (gethostbyname ($host))[4];
	printf "hostaddr=%s\n", &inet_ntoa ($addr);

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


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

Date: Tue, 07 Aug 2001 15:53:10 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Win9.x / Win.me Memory Monitor Via Perl
Message-Id: <3B707156.30DDCF5C@stomp.stomp.tokyo>


Here is a bailing wire script which will allow you to
monitor various memory aspects under Win 9.x/me for
entertainment or comparative analysis.

This script works very nicely for comparing various
code methods, such as comparing a custom read / parse
routine to memory hogging cgi.poopmaker. It does have
sufficient resolution to provide comparative analysis
between strings, arrays, associative arrays and hashes,
fairly much any methods you want to comparative stat.

Use your imagination. You can run multiple instances
of this sub-routine within a script as needed. Use of
a sleep will allow the dust to settle in memory if you
need to slow this routine down.

For you neophytes and Perl 5 Cargo Cultists, this script
does not return statistics for a script in use. It returns
total system statistics; a before and after glance. So don't
pitch an anal retentive fit if your system reflects 80% of
your memory in use; it is not all your script.

To create a statistics report in kilobytes, divide each array
element by 1024. To print in megabytes, divide by 1048576. For
results printed in gigabytes, divide by 1073741824, which is not
suggested for average systems. You may expand my percentages
by grabbing more digits with my substring. Remember, accuracy
decreases with more digits due to floating point methodology.
Better to keep these percentages as is for easy reading.

Easy to use. Include  use Win32::API;  near the top of your
script, copy in my sub-routine at the bottom and, call it
as often as you need with my  &Memory_Statistics;  syntax.

Remember, this is comparative analysis method. This method
of mine will use memory itself. Be sure to run it before
adding code, and after adding code, to standardize results.


Godzilla!
--

#!perl

use Win32::API;

&Memory_Statistics;

sub Memory_Statistics
 {
  my ($raw_stats) = pack ("L8", (0, 0, 0, 0, 0, 0, 0, 0));

  new Win32::API("kernel32", "GlobalMemoryStatus", ["P"], "V") -> Call($raw_stats);
   
  my (@Raw_Stats) = unpack ("L8", $raw_stats);
  shift (@Raw_Stats);

  my ($page_used) = 1 - ($Raw_Stats[4] / $Raw_Stats[3]);
  $page_used = substr ($page_used, 2, 2);

  my ($physical_used) = 1 - ($Raw_Stats[2] / $Raw_Stats[1]);
  $physical_used = substr ($physical_used, 2, 2);

  my ($virtual_used) = 1 - ($Raw_Stats[6] / $Raw_Stats[5]);
  $virtual_used = substr ($virtual_used, 2, 2);


  print "
  Memory Percent Load   : $Raw_Stats[0]%
  \n
  Physical Available    : $Raw_Stats[2]
  Physical Total        : $Raw_Stats[1]
  Physical Percent Used : $physical_used%
  \n
  Virtual Available     : $Raw_Stats[6]
  Virtual Total         : $Raw_Stats[5]
  Virtual Percent Used  : $virtual_used%
  \n
  Page Available        : $Raw_Stats[4]
  Page Total            : $Raw_Stats[3]
  Page Percent Used     : $page_used% \n\n";

 }

exit;


PRINTED RESULTS:
________________


  Memory Percent Load   : 12%


  Physical Available    : 624615424
  Physical Total        : 801800192
  Physical Percent Used : 22%


  Virtual Available     : 2112815104
  Virtual Total         : 2143289344
  Virtual Percent Used  : 01%


  Page Available        : 980262912
  Page Total            : 1048576000
  Page Percent Used     : 06%


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

Date: Tue, 07 Aug 2001 16:07:11 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Win9.x / Win.me Memory Monitor Via Perl
Message-Id: <3B70749F.2380650B@stomp.stomp.tokyo>

Godzilla! wrote:
 
> Here is a bailing wire script....

  "baling wire"

Godzilla!  Queen Of Barbwyre.


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

Date: Tue, 07 Aug 2001 23:06:34 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: Win9.x / Win.me Memory Monitor Via Perl
Message-Id: <Xns90F6A3DFBBDE4cberrycinenetnet1@207.126.101.92>

"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in
news:3B707156.30DDCF5C@stomp.stomp.tokyo: 

>   print "
>   Memory Percent Load   : $Raw_Stats[0]%
>   \n
>   Physical Available    : $Raw_Stats[2]
>   Physical Total        : $Raw_Stats[1]
>   Physical Percent Used : $physical_used%
>   \n
>   Virtual Available     : $Raw_Stats[6]
>   Virtual Total         : $Raw_Stats[5]
>   Virtual Percent Used  : $virtual_used%
>   \n
>   Page Available        : $Raw_Stats[4]
>   Page Total            : $Raw_Stats[3]
>   Page Percent Used     : $page_used% \n\n";

You could make that print a bit prettier using a here-doc  No need for the 
explicit \n sequences if you do it that way.

-- 
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake



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

Date: Tue, 07 Aug 2001 16:46:02 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Win9.x / Win.me Memory Monitor Via Perl
Message-Id: <3B707DBA.E51140A@stomp.stomp.tokyo>

Craig Berry wrote:
 
> Godzilla! wrote:

> >   print "
> >   Memory Percent Load   : $Raw_Stats[0]%
> >   \n
> >   Physical Available    : $Raw_Stats[2]
> >   Physical Total        : $Raw_Stats[1]
> >   Physical Percent Used : $physical_used%
> >   \n
> >   Virtual Available     : $Raw_Stats[6]
> >   Virtual Total         : $Raw_Stats[5]
> >   Virtual Percent Used  : $virtual_used%
> >   \n
> >   Page Available        : $Raw_Stats[4]
> >   Page Total            : $Raw_Stats[3]
> >   Page Percent Used     : $page_used% \n\n";
 
> You could make that print a bit prettier using a here-doc  No need for the
> explicit \n sequences if you do it that way.


Use of here document style makes for an ugly script.

I like my scripts, prints and document sources to
be picture perfect pretty, just like me.


Godzilla!
--
Picture Perfect Pretty Kira
  http://la.znet.com/~callgirl4/cybewire/cybewitc.jpg


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

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


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