[31571] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2830 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 22 18:09:24 2010

Date: Mon, 22 Feb 2010 15:09:08 -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           Mon, 22 Feb 2010     Volume: 11 Number: 2830

Today's topics:
        dprof: alternate path <isaacyho@gmail.com>
    Re: dprof: alternate path <tadmc@seesig.invalid>
    Re: dprof: alternate path <ben@morrow.me.uk>
        how to $doc->createElement with XML::LibXML <zacky.azoulay@gmail.com>
    Re: how to $doc->createElement with XML::LibXML <ben@morrow.me.uk>
    Re: how to $doc->createElement with XML::LibXML <zacky.azoulay@gmail.com>
        retrieve file after posting some data <ron.eggler@gmail.com>
    Re: retrieve file after posting some data <ben@morrow.me.uk>
    Re: retrieve file after posting some data <ron.eggler@gmail.com>
    Re: use strict... sln@netherlands.com
    Re: use strict... <source@netcom.com>
    Re: Using eval to iterate over a set of Perl variables <krishnakumar.perumalla@gmail.com>
        Windows: How to sleep until key is pressed <dilbert1999@gmail.com>
    Re: Windows: How to sleep until key is pressed <derykus@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 22 Feb 2010 13:26:35 -0800 (PST)
From: zikester <isaacyho@gmail.com>
Subject: dprof: alternate path
Message-Id: <bf9d788f-f188-4120-81ec-128f52a6b931@z1g2000prc.googlegroups.com>

How do I use dprof if I don't have permissions to install it to my
perl installation?  I work at a large company and would like to
specify where, in my local disk, the DProf module resides.


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

Date: Mon, 22 Feb 2010 15:39:39 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: dprof: alternate path
Message-Id: <slrnho5u5s.eda.tadmc@tadbox.sbcglobal.net>

zikester <isaacyho@gmail.com> wrote:
> How do I use dprof if I don't have permissions to install it to my
> perl installation?  I work at a large company and would like to
> specify where, in my local disk, the DProf module resides.


    perldoc -q module

        How do I keep my own module/library directory?


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"


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

Date: Mon, 22 Feb 2010 21:43:49 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: dprof: alternate path
Message-Id: <ldab57-nu41.ln1@osiris.mauzo.dyndns.org>


Quoth zikester <isaacyho@gmail.com>:
> How do I use dprof if I don't have permissions to install it to my
> perl installation?  I work at a large company and would like to
> specify where, in my local disk, the DProf module resides.

See local::lib on CPAN, or build your own perl an install it somewhere
you have write access to.

Ben



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

Date: Mon, 22 Feb 2010 12:43:31 -0800 (PST)
From: zacky az <zacky.azoulay@gmail.com>
Subject: how to $doc->createElement with XML::LibXML
Message-Id: <84444165-51a8-4cc5-bf86-d2793a7af1a2@u9g2000yqb.googlegroups.com>

Hi,

i am trying to create a xml file with the following

 <?xml version="1.0" encoding="UTF-8"?>
<file name="file 1"/>
 <file name="file 2"/>

i try the following code without any success, can someone help me to
understand what i am dong wrong?

use strict;
use XML::LibXML;

my $doc = XML::LibXML::Document->new( '1.0', 'UTF-8' );
my $root = $doc->createElementNS('', 'file');
my $attr = $doc->createAttributeNS( "", "name", "file 1" );
$root->setAttributeNodeNS( $attr );
$doc->setDocumentElement($root);
print "\n\n ";
print $doc->toString(2);
print "\n\n ";

my $root2 = $doc->createElementNS('', 'file');
my $attr2 = $doc->createAttributeNS( "", "name", "file 2" );
$root2->setAttributeNodeNS( $attr2 );
$doc->setDocumentElement($root2);
print "\n\n ";
print $doc->toString(2);
print "\n\n ";

the result is

 <?xml version="1.0" encoding="UTF-8"?>
<file name="file 1"/>


 <?xml version="1.0" encoding="UTF-8"?>
<file name="file 2"/>

Regards Zacky


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

Date: Mon, 22 Feb 2010 20:59:48 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: how to $doc->createElement with XML::LibXML
Message-Id: <4r7b57-ba41.ln1@osiris.mauzo.dyndns.org>


Quoth zacky az <zacky.azoulay@gmail.com>:
> 
> i am trying to create a xml file with the following
> 
>  <?xml version="1.0" encoding="UTF-8"?>
> <file name="file 1"/>
>  <file name="file 2"/>

This is not valid XML. An XML document has a *single* root element
containing all the other elements; this has two <file> elements at the
root.

What makes you think you need the XML to look like this?

Ben



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

Date: Mon, 22 Feb 2010 14:03:51 -0800 (PST)
From: zacky az <zacky.azoulay@gmail.com>
Subject: Re: how to $doc->createElement with XML::LibXML
Message-Id: <7bfa3ce0-3ef8-41c5-a9a2-8d36d8091a99@k19g2000yqc.googlegroups.com>

On Feb 22, 10:59=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth zacky az <zacky.azou...@gmail.com>:
>
>
>
> > i am trying to create a xml file with the following
>
> > =A0<?xml version=3D"1.0" encoding=3D"UTF-8"?>
> > <file name=3D"file 1"/>
> > =A0<file name=3D"file 2"/>
>
> This is not valid XML. An XML document has a *single* root element
> containing all the other elements; this has two <file> elements at the
> root.
>
> What makes you think you need the XML to look like this?
>
> Ben

Hi,

Thank, a pmd process is creating an xml like this and i see my problem
the pmd in the root

<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<pmd version=3D"4.2.5" timestamp=3D"2010-02-22T18:24:22.007">
<file name=3D"ContractUploadProcessor.java">
<violation beginline=3D"3" endline=3D"3" begincolumn=3D"1" endcolumn=3D"20"
rule=3D"UnusedImports" ruleset=3D"Import Statement Rules"
package=3D"processors" externalInfoUrl=3D"http://pmd.sourceforge.net/rules/
imports.html#UnusedImports" priority=3D"4">
Avoid unused imports such as 'java.io.File'
</violation>
<file name=3D"ContractCsvEngine.java">
<violation beginline=3D"26" endline=3D"26" begincolumn=3D"1" endcolumn=3D"5=
4"
rule=3D"UnusedImports" ruleset=3D"Import Statement Rules"
package=3D"imports" externalInfoUrl=3D"http://pmd.sourceforge.net/rules/
imports.html#UnusedImports" priority=3D"4">
Avoid unused imports such as 'ataImportActionBo'
</violation>
</file>
</pmd>

thank and Regards Zacky


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

Date: Mon, 22 Feb 2010 14:12:59 -0800 (PST)
From: cerr <ron.eggler@gmail.com>
Subject: retrieve file after posting some data
Message-Id: <e08fcc73-3e8a-4330-b4eb-70363066429a@m27g2000prl.googlegroups.com>

Hi There,

I'm using libwww to post data to a form. Once data is posted, the
server would send me back a file. How can i retrieve and safe this
file?
I'm posting the data with below code:

  $response = $browser->get($url);
  print $response->header('WWW-Authenticate'),"\n";
  die "Error at $url\n ", $response->status_line, "\n Aborting"
  unless $response->is_success;
  #print "Authentication successful!  Got ",$response->content_type, "
document!\n";
  # Create a post request
  my $post = HTTP::Request->new(POST => $PostPage);
  #print "Posting data to \"$PostPage\"\n";
  $post->content_type('application/x-www-form-urlencoded');
  $post->content('export_profile=Current%20Profile');
  # Pass request to the user agent and get a response back
  my $res = $browser->request($post);

  # Check the outcome of the response
  if ($res->is_success) {
      print $res->content , "\n";
  }
  else {
      print $res->status_line, "\n";
  }

How can I wait here until i get a file?
Thanks for hints and suggestions!


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

Date: Mon, 22 Feb 2010 22:36:59 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: retrieve file after posting some data
Message-Id: <bhdb57-7c51.ln1@osiris.mauzo.dyndns.org>


Quoth cerr <ron.eggler@gmail.com>:
> 
> I'm using libwww to post data to a form. Once data is posted, the
> server would send me back a file. How can i retrieve and safe this
> file?
> I'm posting the data with below code:
> 
>   $response = $browser->get($url);
>   print $response->header('WWW-Authenticate'),"\n";
>   die "Error at $url\n ", $response->status_line, "\n Aborting"
>   unless $response->is_success;
>   #print "Authentication successful!  Got ",$response->content_type, "
> document!\n";
>   # Create a post request
>   my $post = HTTP::Request->new(POST => $PostPage);
>   #print "Posting data to \"$PostPage\"\n";
>   $post->content_type('application/x-www-form-urlencoded');
>   $post->content('export_profile=Current%20Profile');
>   # Pass request to the user agent and get a response back
>   my $res = $browser->request($post);
> 
>   # Check the outcome of the response
>   if ($res->is_success) {
>       print $res->content , "\n";
>   }
>   else {
>       print $res->status_line, "\n";
>   }
> 
> How can I wait here until i get a file?
> Thanks for hints and suggestions!

The file returned from the server should be in the $res object. See the
documentation for HTTP::Response.

Ben



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

Date: Mon, 22 Feb 2010 14:58:07 -0800 (PST)
From: cerr <ron.eggler@gmail.com>
Subject: Re: retrieve file after posting some data
Message-Id: <19f0900a-b4fa-4031-acc7-6798828f9682@f17g2000prh.googlegroups.com>

On Feb 22, 2:36=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth cerr <ron.egg...@gmail.com>:
>
>
>
>
>
>
>
> > I'm using libwww to post data to a form. Once data is posted, the
> > server would send me back a file. How can i retrieve and safe this
> > file?
> > I'm posting the data with below code:
>
> > =A0 $response =3D $browser->get($url);
> > =A0 print $response->header('WWW-Authenticate'),"\n";
> > =A0 die "Error at $url\n ", $response->status_line, "\n Aborting"
> > =A0 unless $response->is_success;
> > =A0 #print "Authentication successful! =A0Got ",$response->content_type=
, "
> > document!\n";
> > =A0 # Create a post request
> > =A0 my $post =3D HTTP::Request->new(POST =3D> $PostPage);
> > =A0 #print "Posting data to \"$PostPage\"\n";
> > =A0 $post->content_type('application/x-www-form-urlencoded');
> > =A0 $post->content('export_profile=3DCurrent%20Profile');
> > =A0 # Pass request to the user agent and get a response back
> > =A0 my $res =3D $browser->request($post);
>
> > =A0 # Check the outcome of the response
> > =A0 if ($res->is_success) {
> > =A0 =A0 =A0 print $res->content , "\n";
> > =A0 }
> > =A0 else {
> > =A0 =A0 =A0 print $res->status_line, "\n";
> > =A0 }
>
> > How can I wait here until i get a file?
> > Thanks for hints and suggestions!
>
> The file returned from the server should be in the $res object. See the
> documentation for HTTP::Response.
>
Hi Ben,

Yep, been looking at that too but I haven't really gotten any further
unfortunately :( $res->filename e.g. is returning the filename of the
script i'm posting to but not the filename the server is sending back.
I don't know how i'd get the data. Been playing with
decoded_content('none') as well (cause the file coming back is in
binary) - but no success either - anymore hints maybe?

Thanks!

--
roN


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

Date: Mon, 22 Feb 2010 07:22:40 -0800
From: sln@netherlands.com
Subject: Re: use strict...
Message-Id: <7p75o5hu7e8sfopn1g4tvkv72d4uvl83ss@4ax.com>

On Sun, 21 Feb 2010 11:22:31 -0600, Tad McClellan <tadmc@seesig.invalid> wrote:

[snip]

>Since Robin (and, I assume, you) do not know why you would _not_ use strict, 
>you _should_ use strict.  :-)

Then it might be better to know circumstances one wouldn't use strict in
relation to vars, subs, refs, performance, debug, production, bugs, versions,
etc ... There has to be a starting point for full understanding.

-sln


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

Date: Mon, 22 Feb 2010 07:47:32 -0800
From: David Harmon <source@netcom.com>
Subject: Re: use strict...
Message-Id: <88ednaxiMsGJOh_WnZ2dnUVZ_jSdnZ2d@earthlink.com>

On Mon, 22 Feb 2010 07:22:40 -0800 in comp.lang.perl.misc,
sln@netherlands.com wrote,
>On Sun, 21 Feb 2010 11:22:31 -0600, Tad McClellan <tadmc@seesig.invalid> wrote:
>
>[snip]
>
>>Since Robin (and, I assume, you) do not know why you would _not_ use strict, 
>>you _should_ use strict.  :-)
>
>Then it might be better to know circumstances one wouldn't use strict in
>relation to vars, subs, refs, performance, debug, production, bugs, versions,
>etc ... There has to be a starting point for full understanding.

Decades of non-perl programming shows me plenty of reason to "use
strict" in my own perl code.  Tad is right that I really don't see the
reason ever not to, but I suppose I'll see it when or if I ever run into
it.

As for breaking existing code, some of that breakage probably uncovers
existing bugs.  If it breaks, it's not following perlstyle
recommendations anyway.


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

Date: Mon, 22 Feb 2010 10:42:51 -0800 (PST)
From: krish <krishnakumar.perumalla@gmail.com>
Subject: Re: Using eval to iterate over a set of Perl variables
Message-Id: <c844466d-13b4-4549-b2cf-3d321addfc49@g8g2000pri.googlegroups.com>

Hi Henry,

   Due to the use of single quotes '', the perl variables don't get
the values of the variables. Example:

my $string =3D "Hello";

print '$string'; # this would print $string on the console/tty.
print "$string"; #this would print Hello on the console/tty.

Is that what you are looking at? Let me know if I mis-interpreted the
question.

--
Krishna


On Feb 21, 6:27=A0pm, Henry Law <n...@lawshouse.org> wrote:
> (I'm sure Google should have been able to help me with this but
> structuring a suitable query defeated me... a million hits or none.)
>
> I'm inserting new records into a MYSQL database using Perl DBI. =A0There
> are fourteen fields, each one of which has its corresponding variable in
> my program. =A0I want to execute the "bind_param" method for each one of
> them. =A0If you're not familiar with DBI here's an example of what I migh=
t
> code:
> =A0 =A0$sth->bind_param( 1, $message_id );
> =A0 =A0$sth->bind_param( 2, $from_name );
> =A0 =A0...
> =A0 =A0$sth->bind_param( 14, $body );
>
> Ugly. =A0So I have a list of those variable names, thus
> =A0 =A0my @variable_name_list =3D ( '$message_id', '$from_name', ...
> and I have a loop with a counter, like this
> =A0 =A0for ( my $i =3D 1; $i<=3D14; $i++ ) {
> =A0 =A0 =A0 =A0eval{ $ins_sth->bind_param( $i, $variable_name_list[$i-1] =
) };
> =A0 =A0}
>
> ... but the database is filling up with fields containing the literal
> name of my variables:
>
> =A0 =A0mysql> SELECT message_id FROM mailitem;
> =A0 =A0+-------------+
> =A0 =A0| message_id =A0|
> =A0 =A0+-------------+
> =A0 =A0| $message_id |
> =A0 =A0+-------------+
>
> I know that it's to do with when the variable name "becomes" the
> variable value, but I've tried multiple combinations of $, \$, and
> nested 'eval' and can't hit it. =A0Can someone help me work out how to do
> this? =A0Yes, I could have coded fourteen statements and had it working b=
y
> now, but it's a matter of elegance!
>
> --
>
> Henry Law =A0 =A0 =A0 =A0 =A0 =A0Manchester, England



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

Date: Mon, 22 Feb 2010 12:23:45 -0800 (PST)
From: Dilbert <dilbert1999@gmail.com>
Subject: Windows: How to sleep until key is pressed
Message-Id: <b51f1073-e7e0-47b2-83a8-55006e2e27e8@k19g2000yqc.googlegroups.com>

I have a perl program (under windows vista) that records every
scancode / keystroke I make (it even records when I hit the Ctrl-key,
the Shift-key, F1, F2, etc....

So the program works ok for me, but it has a "do{...}until" loop that
better should be replaced by a sleep command. My concern is that I
waste a lot of CPU cycles in the do{...}until loop, that could be
avoided if I replace that loop by a sleep command

How can I achieve this ? does such a command exist under windows ?
(just in case you might ask: I already tried each and every option in
Term::Readkey, it definitely does not record when I hit the Ctrl-key,
Shift-key, etc...) Fortunately, Win32::Console does the job quite
well, it is just the do{...}until loop that bothers me because it
wastes CPU cycles.

Here is the program:

use strict;
use warnings;

use Win32::Console;

my $CONS_INP = Win32::Console->new(STD_INPUT_HANDLE);

while (1) {

    # I want to sleep here until a key is pressed...
    # How can I achieve this under Windows... ???

    my @event;
    do {
        @event = $CONS_INP->Input() if $CONS_INP->GetEvents();
    } until @event;

    local $" = "', '";
    print "event = ('@event')\n";

    last if $event[5] == 27; # Escape key
}

Is there a perl module for windows that allows me to sleep (or wait ?)
until a key is pressed (even if it is the Ctrl-key, or the Shift-key)


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

Date: Mon, 22 Feb 2010 13:12:04 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Windows: How to sleep until key is pressed
Message-Id: <10d4d431-4be5-40d0-9e19-249a56af6ad8@e19g2000prn.googlegroups.com>

On Feb 22, 12:23=A0pm, Dilbert <dilbert1...@gmail.com> wrote:
> I have a perl program (under windows vista) that records every
> scancode / keystroke I make (it even records when I hit the Ctrl-key,
> the Shift-key, F1, F2, etc....
>
> So the program works ok for me, but it has a "do{...}until" loop that
> better should be replaced by a sleep command. My concern is that I
> waste a lot of CPU cycles in the do{...}until loop, that could be
> avoided if I replace that loop by a sleep command
>
> How can I achieve this ? does such a command exist under windows ?
> (just in case you might ask: I already tried each and every option in
> Term::Readkey, it definitely does not record when I hit the Ctrl-key,
> Shift-key, etc...) Fortunately, Win32::Console does the job quite
> well, it is just the do{...}until loop that bothers me because it
> wastes CPU cycles.
>
> Here is the program:
>
> use strict;
> use warnings;
>
> use Win32::Console;
>
> my $CONS_INP =3D Win32::Console->new(STD_INPUT_HANDLE);
>
> while (1) {
>
> =A0 =A0 # I want to sleep here until a key is pressed...
> =A0 =A0 # How can I achieve this under Windows... ???
>
> =A0 =A0 my @event;
> =A0 =A0 do {
> =A0 =A0 =A0 =A0 @event =3D $CONS_INP->Input() if $CONS_INP->GetEvents();
> =A0 =A0 } until @event;
>
> =A0 =A0 local $" =3D "', '";
> =A0 =A0 print "event =3D ('@event')\n";
>
> =A0 =A0 last if $event[5] =3D=3D 27; # Escape key
>
> }
>
> Is there a perl module for windows that allows me to sleep (or wait ?)
> until a key is pressed (even if it is the Ctrl-key, or the Shift-key)

Win32 5.10.1 seems to understand sleep();

    do {
        @event =3D ...
        sleep 1;
    } until @event;

At least, hitting Ctrl-C interrupts the above. Don't know if
this'll do everything you need though.

--
Charles DeRykus



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

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:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 2830
***************************************


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