[25256] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7501 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 9 14:05:53 2004

Date: Thu, 9 Dec 2004 11:05:09 -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, 9 Dec 2004     Volume: 10 Number: 7501

Today's topics:
    Re: Convert text to Hex <jwillmore@fastmail.us>
    Re: Convert text to Hex <jwillmore@fastmail.us>
    Re: Convert text to Hex <this.address@is.invalid>
    Re: Convert text to Hex <jwillmore@fastmail.us>
    Re: Convert text to Hex <this.address@is.invalid>
    Re: die'ing with the caller's line number (Peter Scott)
    Re: Dynamic Search Tool <newsgroups@xtracold.co.uk>
    Re: examples using PDF::Template <botfood@yahoo.com>
    Re: examples using PDF::Template <nuba@robalo.dcc.ufmg.br>
    Re: Facile user-agent statistics tool <aditya.singh@gmail.com>
    Re: Facile user-agent statistics tool <apeiron+usenet@coitusmentis.info>
    Re: Facile user-agent statistics tool <apeiron+usenet@coitusmentis.info>
    Re: Facile user-agent statistics tool <1usa@llenroc.ude.invalid>
    Re: Facile user-agent statistics tool <1usa@llenroc.ude.invalid>
    Re: Facile user-agent statistics tool <rob@nova.hbx.us>
    Re: Facile user-agent statistics tool <apeiron+usenet@coitusmentis.info>
    Re: FAQ 4.22: How do I expand function calls in a strin <nobull@mail.com>
    Re: How to detect an undefined SV* value in XS? xhoster@gmail.com
    Re: Is this possible in perl? <nobull@mail.com>
    Re: Perl to MySQL? <aditya.singh@gmail.com>
        Recognize directories and files. (Mitchell Hulscher)
    Re: Recognize directories and files. <mritty@gmail.com>
    Re: Recognize directories and files. <glex_nospam@qwest.invalid>
        Reg Hash of Hash <shashank@mia.ece.uic.edu>
    Re: regular expressions problem <bill@karwin.com>
        Retrieving web pages (Dackle)
    Re: Retrieving web pages <lawshouse.public@btconnect.com>
    Re: Retrieving web pages <simon.dukes@gmail.com>
    Re: Using MIME::Lite  for multipart message - trouble w <mritty@gmail.com>
    Re: Using MIME::Lite  for multipart message - trouble w <noreply@gunnar.cc>
    Re: Using MIME::Lite for multipart message - trouble wi <alamukutty@gmail.com>
    Re: Using MIME::Lite for multipart message - trouble wi <alamukutty@gmail.com>
    Re: Using MIME::Lite for multipart message - trouble wi <noreply@gunnar.cc>
    Re: Using MIME::Lite for multipart message - trouble wi <noreply@gunnar.cc>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 09 Dec 2004 11:11:18 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: Convert text to Hex
Message-Id: <pan.2004.12.09.16.11.16.718114@fastmail.us>

On Thu, 09 Dec 2004 05:06:28 -0800, zvika wrote:

> How can I want to convert this text:
> 
> 01  SYSOT    VALUE '^@^X^@^A^@^AA'         PIC X(07).
> 
> To:
> 
> 01  SYSOT    VALUE X'001800010001C1' PIC X(07).
> (This is the eqvivalent hex values.)

I can get you part way there.  This will take into account that you are
trying to convert from one COBOL representation into another (because most
of the responses you have gotten are dealing with the whole value versus
the 7 values you want - as depicted by the PICTURE).  Sadly, I don't get
the values you described from within the script.  Maybe someone can point
out what's wrong.

HTH

Jim

#!/usr/bin/perl

use strict;
use warnings;

my $string = <<EOL;
01  SYSOT    VALUE '^@^X^@^A^@^AA'         PIC X(07).
EOL

#remove single quotes
$string =~ s/\'//g;

#break $string into it's white space deliminated parts
my @parts = split /\s+/, $string;

#the PIC values; '^char' with '\cchar '
$parts[3] =~ s/\^(.{1})/\\c$1 /g;

#spilt the PIC value into component parts
my @pic_value = split /\s+/, $parts[3];

#reconstruct the PIC value with appropriate substitution
my $new_pic_value = "VALUE X'";
foreach my $current(@pic_value) {
  print "($current)\n";
  #I'm not sure how to convert something like ^@ into hex :-(
  $new_pic_value .= sprintf "%X", ord($current);
}
$new_pic_value .= "'";

#replace old PIC value with new PIC value
$parts[3] = $new_pic_value;

print "new pic value: ",join("", $new_pic_value),"\n";
print join(" ", @parts),"\n";



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

Date: Thu, 09 Dec 2004 11:26:41 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: Convert text to Hex
Message-Id: <pan.2004.12.09.16.26.41.502818@fastmail.us>

On Thu, 09 Dec 2004 11:11:18 -0500, James Willmore wrote:

< ...>
> print "new pic value: ",join("", $new_pic_value),"\n";

This line should be ...
print "new pic value: $new_pic_value\n";

Opps!


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

Date: Thu, 9 Dec 2004 16:42:15 +0000
From: Stephane CHAZELAS <this.address@is.invalid>
Subject: Re: Convert text to Hex
Message-Id: <slrncrh037.9nh.stephane.chazelas@spam.is.invalid>

2004-12-09, 11:11(-05), James Willmore:
[...]
>> 01  SYSOT    VALUE '^@^X^@^A^@^AA'         PIC X(07).
[...]
>   #I'm not sure how to convert something like ^@ into hex :-(
[...]

^@, ^A, ... ^_, ^? is one usual representation of characters
\0..\037,\0177.

^<n> being actually ord(<n>) & ~64. ^X would then be the
character \030.

Hence the:

s/VALUE '(.*?)'/"VALUE X'" . unpack("H*", $1) . "'"/e

I was suggesting.

-- 
Stephane


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

Date: Thu, 09 Dec 2004 12:16:53 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: Convert text to Hex
Message-Id: <pan.2004.12.09.17.16.52.360513@fastmail.us>

On Thu, 09 Dec 2004 16:42:15 +0000, Stephane CHAZELAS wrote:

> 2004-12-09, 11:11(-05), James Willmore:
> [...]
>>> 01  SYSOT    VALUE '^@^X^@^A^@^AA'         PIC X(07).
> [...]
>>   #I'm not sure how to convert something like ^@ into hex :-(
> [...]
> 
> ^@, ^A, ... ^_, ^? is one usual representation of characters
> \0..\037,\0177.
> 
> ^<n> being actually ord(<n>) & ~64. ^X would then be the
> character \030.
> 
> Hence the:
> 
> s/VALUE '(.*?)'/"VALUE X'" . unpack("H*", $1) . "'"/e
> 
> I was suggesting.

And ... when the following is run ...

#!/usr/bin/perl

use strict;
use warnings;

my $string = <<EOL;
01  SYSOT    VALUE '^@^X^@^A^@^AA'         PIC X(07).
EOL

$string =~ s/VALUE '(.*?)'/"VALUE X'" . unpack("H*", $1) . "'"/e;
print "$string\n";

 ... produces ...

[jim@localhost clpm]$ perl hex.pl
01  SYSOT    VALUE X'5e405e585e405e415e405e4141'         PIC X(07).

[jim@localhost clpm]$ 

 ... which isn't what the OP wanted :-)

To complicate things, he appears to be using EBCDIC, not ASCII values as
the final result.  '41' is 'A' in ASCII, but in EBCDIC it's represented by
'C1'.  And, in your solution, you don't appear to take into account that
'^' is a control character (much like the infamous '^M' you get when
getting a DOS file and placing it in binary format on a Unix box).

Close ... but no cigar :-)

Jim


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

Date: Thu, 9 Dec 2004 17:56:50 +0000
From: Stephane CHAZELAS <this.address@is.invalid>
Subject: Re: Convert text to Hex
Message-Id: <slrncrh4f2.9nh.stephane.chazelas@spam.is.invalid>

2004-12-09, 12:16(-05), James Willmore:
[...]
>>>> 01  SYSOT    VALUE '^@^X^@^A^@^AA'         PIC X(07).
[...]
>> ^<n> being actually ord(<n>) & ~64. ^X would then be the
>> character \030.
>> 
>> Hence the:
>> 
>> s/VALUE '(.*?)'/"VALUE X'" . unpack("H*", $1) . "'"/e
>> 
>> I was suggesting.
>
> And ... when the following is run ...
[...]
> my $string = <<EOL;
> 01  SYSOT    VALUE '^@^X^@^A^@^AA'         PIC X(07).
> EOL
>
> $string =~ s/VALUE '(.*?)'/"VALUE X'" . unpack("H*", $1) . "'"/e;
> print "$string\n";
>
> ... produces ...
>
> [jim@localhost clpm]$ perl hex.pl
> 01  SYSOT    VALUE X'5e405e585e405e415e405e4141'         PIC X(07).

I actually meant that "^@^X^@^A^@^AA" was actually the character
0x00 followed by the character 0x18... Such characters can't be
included in newsgroup messages, neither can't they generally be
seen, hence the need of a representations such as ^@, ^X.

[...]
> ... which isn't what the OP wanted :-)
>
> To complicate things, he appears to be using EBCDIC, not ASCII values as
> the final result.  '41' is 'A' in ASCII, but in EBCDIC it's represented by
> 'C1'.  And, in your solution, you don't appear to take into account that
> '^' is a control character (much like the infamous '^M' you get when
> getting a DOS file and placing it in binary format on a Unix box).
[...]

I took it into account, that's what I explained. ^X (aka Ctrl-X)
is the character 0x18. I assumed the ^X in OP's message was
actually the representation of the 0x18 character.

You're right however about the EBCDIC issue.

However if his system charset is EBCDIC (which the fact that he
said that the result should be the hex representation suggests),
my code would still work (pack("H*", "A") would return "C1").

$ cat -vt input-file
01  SYSOT    VALUE '^@^X^@^A^@^AA'         PIC X(07)
$ od -tc input-file
0000000   0   1           S   Y   S   O   T                   V   A   L
0000020   U   E       '  \0 030  \0 001  \0 001   A   '
0000040                       P   I   C       X   (   0   7   )  \n
0000057
$ cat perl-script
s/VALUE '(.*?)'/"VALUE X'" . unpack("H*", $1) . "'"/e
~$ perl -p perl-script input-file
01  SYSOT    VALUE X'00180001000141'         PIC X(07)

-- 
Stephane




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

Date: Thu, 09 Dec 2004 16:05:09 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: die'ing with the caller's line number
Message-Id: <VI_td.469998$%k.364401@pd7tw2no>

In article <1102541384.608648.248460@f14g2000cwb.googlegroups.com>,
 carloschoenberg@yahoo.com writes:
>With DBI, it seems that if I want to use the "?" placeholders that I
>must
>use prepare and execute. So I made a simple helper function to do both
>for
>me, saving some typing and making the code slightly cleaner:
>
>sub sql_do($@) {
>my $q = shift;
>
>my $sth = $dbh->prepare($q);
>$sth->execute(@_);
>}
>
>
>But I run with AutoRaise on, and when I hit a fatal error, I get a line
>number
>inside of sql_do(), which is rarely useful.
>
>What should I do to get the line number of the call to sql_do() when
>sql_do()'s call to execute fails?

As has been pointed out, if you confess() on die, you'll get the
stack trace.  If you want just the one line number output, though,
out of some desire to be neat, you could try putting sql_do() in 
its own package and putting that package name in @Carp::CARP_NOT.  
Note: I haven't tried this, I'm just going off documentation in 
5.8 versions of Carp.pm:

       Here is a more complete description of how shortmess works.
       [...]
       2.  Packages claim that there won't be errors on calls to or from pack-
           ages explicitly marked as safe by inclusion in @CARP_NOT, or (if
           that array is empty) @ISA.  The ability to override what @ISA says
           is new in 5.8.

Or you could turn off AutoRaise inside sql_do(), do the execute, 
test for an error, and croak() yourself if you find one, otherwise turn
AutoRaise back on...

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/


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

Date: 9 Dec 2004 11:02:01 -0800
From: "xtracold" <newsgroups@xtracold.co.uk>
Subject: Re: Dynamic Search Tool
Message-Id: <1102616398.879110.296890@c13g2000cwb.googlegroups.com>


James Willmore wrote:
> On Wed, 08 Dec 2004 00:20:24 -0800, xtracold wrote:
>
> <...>
> > I'm not looking for a written solution, i'm looking for peoples
past
> > experience of binding to each keystroke event in an Tk::Entry
widget
> > and what performance I can expect. Perhaps there is another
existing
> > add-on that I don't know about that already does this?
>
> Might I suggest that you take the above posting and re-post it to a
more
> appropriate newsgroup - comp.lang.perl.tk
>
> Or, just read the Tk::Entry documentation and any documentation the
> Tk::Entry documentation references, write some code, see how it
works,
> maybe do some benchmarking ... you know, see for yourself :-)
>
> I can say this - depending upon what you're trying to do, there are
> widgets that have builtin key bindings that aid in making a robust
bit of
> code.  For example, the Tk::Text widget has a very nice right-mouse
click
> menu ready to use that include the ability to go to a particular line
of a
> file.  I believe that it also has the more common keystroke bindings
(like
> "Ctrl-C" to copy text and "Ctrl-V" to paste).
>
> And I have found "Mastering Perl/Tk" (O'Reilly publishes this book -
> *not* the "Learning Perl/Tk" book ... it's not as helpful as
"Mastering
> Perl/Tk") to be a very good reference with losts of good examples.
This,
> of course, is if you want to but a book :-)
>
> HTH
>
> Jim

Thanks Jim, in the end I just put together something simple and it
seemed to work. If I remember i'll post what I did on the Tk newsgroup
when I get to work tomorrow!



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

Date: 9 Dec 2004 08:07:28 -0800
From: "botfood" <botfood@yahoo.com>
Subject: Re: examples using PDF::Template
Message-Id: <1102608448.432750.14870@f14g2000cwb.googlegroups.com>

 ...after looking at what available, I'm a little confused about what to
do next. I have an old version of perl from Activestate that I use for
development (5.005 build 522) as a lowest common denominator. I am not
SURE what version my usual webhost as installed, but its probably 5.6
or 5.8 by now?

anyway, the issue is that while PostScript::Simple is listed on CPAN,
it is NOT in the activestate download ppm. there is a similar package
PostScript, but only compiled for perl 5.8 and by a different author
with different methods.

so.... I am unsure which way to go that would allow me to code and test
at home on my PC and have the most likely chance of asking my webhost
to install if they haven't already.

PostScript  from activestate, or PostScript::Simple from CPAN ???? and
how do I get either of them running on my PC under old perl without
having compilers and all that?



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

Date: Thu, 9 Dec 2004 18:50:23 +0000 (UTC)
From: Nuba <nuba@robalo.dcc.ufmg.br>
Subject: Re: examples using PDF::Template
Message-Id: <cpa6pf$5f8$1@dcc.ufmg.br>

botfood <botfood@yahoo.com> wrote:
: I think the printer will accept either PostScript or eps files. Looks
: like a much cleaner solution than .pdf !

Then maybe it's worth looking at the Template Toolkit 
(namespace Template at CPAN)

Some links:
http://www.template-toolkit.org/examples/ps/index.html
http://www.template-toolkit.org/info.html

-- 
         ,::::,                                                   
        ::    :    Nuba Rodrigues Princigalli    _____________    
        :. O-O:                                 |        '\\\\\\  
         :   >     Web Design and Development   |        ' ____|_ 
     ____\  - ._.   Computational Mathematics   |   +    '||::::::
   /'    \ -::' .'                              |        '||_____|
  /. ,-    O    < \               www.nuba.tk   '________|_____|  
 (\ <'     '  |\ / '-.___    nuba@dcc.ufmg.br   ___/____|___\___  
_.\__\________\_\___/), |\\____________________|    _    '  <<<:| 
                                               |_________'___o_o| 


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

Date: 9 Dec 2004 08:46:24 -0800
From: "AD" <aditya.singh@gmail.com>
Subject: Re: Facile user-agent statistics tool
Message-Id: <1102610784.773747.185070@c13g2000cwb.googlegroups.com>

Two small things.
1.  my $from_header  =
qr/From:.*?([A-Za-z0-9\.]+@[A-Za-z0-9\.]+)\s*.*/;
This won't catch email addresses having '_', or '-'.
More importantly see $perldoc -q 'mail address'

2.  if ( -f $file_name && $file_name !~ /\/\./ ) {
Writing reguilar expression like "$file_name !~ /\/\./ " makes
obfuscates code. You can use other delimiters like # etc.



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

Date: 9 Dec 2004 16:50:36 GMT
From: Christopher Nehren <apeiron+usenet@coitusmentis.info>
Subject: Re: Facile user-agent statistics tool
Message-Id: <slrncrh0is.6g4.apeiron+usenet@prophecy.dyndns.org>

On 2004-12-09, Robert Manea scribbled these
curious markings:
> Summary:
>         - 2141 postings in total
            ^^^^
 ... What? That's a ridiculously small sampling of posts. My news server
(news.individual.net, it's free) provides 15k articles for clpm, and
those articles are numbered between approximately 530k and 550k. One of
the most basic rules of statistics is to take a reasonably-sized sample.
Statistics based upon a small sampling represent exactly that: a small
sample of what's available.

Best Regards,
Christopher Nehren
-- 
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated".  -- Ken Thompson
If you ask the wrong questions, you get answers like "42" and "God".
Unix is user friendly. However, it isn't idiot friendly.


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

Date: 9 Dec 2004 17:05:04 GMT
From: Christopher Nehren <apeiron+usenet@coitusmentis.info>
Subject: Re: Facile user-agent statistics tool
Message-Id: <slrncrh1e0.6jk.apeiron+usenet@prophecy.dyndns.org>

On 2004-12-09, AD scribbled these
curious markings:
> Two small things.
> 1.  my $from_header  =
> qr/From:.*?([A-Za-z0-9\.]+@[A-Za-z0-9\.]+)\s*.*/;
> This won't catch email addresses having '_', or '-'.
> More importantly see $perldoc -q 'mail address'

Or + characters, like mine.

Best Regards,
Christopher Nehren
-- 
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated".  -- Ken Thompson
If you ask the wrong questions, you get answers like "42" and "God".
Unix is user friendly. However, it isn't idiot friendly.


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

Date: 9 Dec 2004 17:25:07 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Facile user-agent statistics tool
Message-Id: <Xns95BA7E549BEA4asu1cornelledu@132.236.56.8>

Robert Manea <rob@nova.hbx.us> wrote in
news:8cr9pc.cmk.ln@rob.unisolblade.de: 

> ---8<---------------------------------------------------------------8<-
> -- 
> 
> Example output for comp.lang.perl.misc:
> 
>   1. Microsoft Outlook Express  :  81
>   2. Mozilla                    :  35
>   3. Mozilla Thunderbird        :  33
>   4. G2                         :  32
>   5. slrn                       :  25
>   6. KNode                      :  21
>   7. Gnus                       :  19
>   8. Pan                        :  17
>   9. Forte Agent                :  15
>  10. tin                        :  12
> [...]

Am I the only one who uses XNews?

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: 9 Dec 2004 17:28:13 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Facile user-agent statistics tool
Message-Id: <Xns95BA7EDBA45FCasu1cornelledu@132.236.56.8>

Christopher Nehren <apeiron+usenet@coitusmentis.info> wrote in 
news:slrncrh0is.6g4.apeiron+usenet@prophecy.dyndns.org:

> On 2004-12-09, Robert Manea scribbled these
> curious markings:
>> Summary:
>>         - 2141 postings in total
>             ^^^^
> ... What? That's a ridiculously small sampling of posts. My news server
> (news.individual.net, it's free) provides 15k articles for clpm, and
> those articles are numbered between approximately 530k and 550k. One of
> the most basic rules of statistics is to take a reasonably-sized 
> ample. Statistics based upon a small sampling represent exactly that: a 
> small sample of what's available.


Actually, 2000 postings out of 20000 is a very large sample. The crucial 
factor in determining whether a sample is usable or not is whether it was 
randomly selected, not its size.

http://college.hmco.com/history/readerscomp/rcah/html/ah_071900
_publicopinio.htm

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Thu, 9 Dec 2004 18:54:53 +0100
From: Robert Manea <rob@nova.hbx.us>
Subject: Re: Facile user-agent statistics tool
Message-Id: <dh3apc.s0l.ln@rob.unisolblade.de>

Segfault in module "A. Sinan Unur" - dump details are as follows:

> Am I the only one who uses XNews?

  1. Microsoft Outlook Express  :  82
  2. Mozilla                    :  35
  3. G2                         :  35
  4. Mozilla Thunderbird        :  33
  5. slrn                       :  27
  6. KNode                      :  21
  7. Gnus                       :  19
  8. Pan                        :  17
  9. Forte Agent                :  15
 10. tin                        :  12
 11. Xnews                      :  7      <--- No, you aren't. :)
 12. trn                        :  6
 13. MT-NewsWatcher             :  5
 14. nn                         :  4
 15. Opera M2                   :  4
 16. 40tude_Dialog              :  2
 17. Thoth                      :  2
 18. MicroPlanet-Gravity        :  2
 19. Microsoft-Entourage        :  1
 20. vBulletin USENET gateway   :  1
 21. ProNews                    :  1
 22. trn                        :  1
 23. Forte Free Agent           :  1
 24. hidden                     :  1
 25. xrn                        :  1
 26. Messenger-Pro              :  1
 27. Thunderbird                :  1
 28. Sylpheed version           :  1
 29. NewsLeecher                :  1
 30. Sylpheed-Claws             :  1

Summary:
        - 2181 postings in total
        - 30 different neawsreaders in 340 distinct postings
        - Average of 5.582 articles per poster (with agent header)
        - 283 without User Agent header


Done with a slightly fixed $from_header regex.
my $from_header  = qr/From:.*?([A-Za-z0-9\._\-\+]+@[A-Za-z0-9\._\-\+]+)\s*.*/;

As I want to catch 'slightly' non conforming email adresses as well a
standard compliant parsers would be rather contraproductive to the
quality of the results, I guess.

Anyways, the sole purpose of the address is to server as a unique
identifier for each poster. Thus compliance to standards isn't that much
necessary in this case..


  Greets, Rob

-- 
The Enterprise meets God, and it's a child, a computer, or a C program.


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

Date: 9 Dec 2004 18:27:00 GMT
From: Christopher Nehren <apeiron+usenet@coitusmentis.info>
Subject: Re: Facile user-agent statistics tool
Message-Id: <slrncrh67k.6vu.apeiron+usenet@prophecy.dyndns.org>

On 2004-12-09, Robert Manea scribbled these
curious markings:

[...]

>   4. Mozilla Thunderbird        :  33

[...]

>  12. trn                        :  6

[...]

>  22. trn                        :  1
>  27. Thunderbird                :  1
>  28. Sylpheed version           :  1

[...]

>  30. Sylpheed-Claws             :  1

I hope that you like dealing with inconsistencies. :)

Best Regards,
Christopher Nehren
-- 
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated".  -- Ken Thompson
If you ask the wrong questions, you get answers like "42" and "God".
Unix is user friendly. However, it isn't idiot friendly.


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

Date: Thu, 09 Dec 2004 17:58:34 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: FAQ 4.22: How do I expand function calls in a string?
Message-Id: <cpa3f6$c5p$1@sun3.bham.ac.uk>



PerlFAQ Server wrote:
> 
> 4.22: How do I expand function calls in a string?

>     See also ``How can I expand variables in text strings?'' in this section
>     of the FAQ.

This "See also" is inappropriate.  Appart from a superficially similar 
wording the questions are unrealted[1].  On referrs to interpolation in 
double quoted strings in code, the other to expanding things in data. 
There is nothing in the answer to either one of these questions that 
helps understand the other.

[1] Actually if the answer to the question "How can I expand variables 
in text strings?" mentioned the simple/obvious eval solution then there 
would be a case for that answer to advise he reader to see also "How do 
I expand function calls in a string?" so that they could see how eval 
could be abused.  However the answer currently given to "How can I 
expand variables in text strings?" does not mention using the 
simple/obvious solution there's no reason for a "see also" link, and 
even if there were it would be a link in the other direction only.



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

Date: 09 Dec 2004 17:24:49 GMT
From: xhoster@gmail.com
Subject: Re: How to detect an undefined SV* value in XS?
Message-Id: <20041209122449.630$E9@newsreader.com>

"Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de> wrote:
> Also sprach xhoster@gmail.com:
> >>
> >> if (SvTYPE(sv) == SVt_NULL)  printf("Undefined");
> >> # Contributed by Rob (Sisyphus):
> >> if (SvANY(sv) == NULL)  printf("Undefined");
> >> # Contributed by Tassilo v. Parseval:
> >> if (SvOK(sv) == false)  printf("Undefined");
> >>
> >> Of these three methods, only SvOK is documented in "perldoc
> >> perlapi", which is worth considering if portability is a concern.  But
> >> I tested all three methods, and they all seem to work.
> >> Thanks for all who replied!
> >
> > SvANY doesn't seem to work properly for me.
>
> Of course it doesn't. It's just not the proper way to test for
> undefinedness.

Right, that is what I said.

> I said elsewhere to use SvOK as it will do what you want, namely check
> the flags of the SV. I am not entirely sure why you insist on doing it
> the hard and wrong way.

I don't insist on doing it any way.  I was just notifying the person I
replied to that what he assumes works doesn't actually work.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 09 Dec 2004 18:39:27 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Is this possible in perl?
Message-Id: <cpa5rv$d94$1@sun3.bham.ac.uk>



Scott W Gifford wrote:

> You can use symbolic references, which will allow any function to be
> called:
> 
>     {
>       no strict 'refs';
>       $func = $xml->get_func_name();
>       $func->();
>     }
> 
> But the most secure way would be to use "hard references" and make a
> hash of allowed functions, mapping names to the reference:
> 
>     my %allowed_funcs = (
>       func1 => \&func1,
>       func2 => \&func2,
>     );
>     $func = $xml->get_func_name();
>     $allowed_funcs{$func} or die "Can't run '$func'";
>     $allowed_funcs{$func}->();
> 
> That gives you precise control over what functions can be called, and
> will run just fine under taint mode, "use strict", and "use warnings".

You can keep the precise control and avoid the uglnessess of having to 
list all the allowed funcs thrice by simply defining all the allowed 
functions with a package prefix that you do not use for anything else.
This way you use get Perl to put the functions directly into a dispatch 
table called %My::Module::XMLfunc:: and avoid the need to copy them into 
another hash.

sub My::Module::XMLfunc::func1 {
   # do stuff...
}

#...
      {
        no strict 'refs';
        $func = $xml->get_func_name();
        "My::Module::XMLfunc::$func"->();
      }



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

Date: 9 Dec 2004 08:27:17 -0800
From: "AD" <aditya.singh@gmail.com>
Subject: Re: Perl to MySQL?
Message-Id: <1102609637.117901.98950@c13g2000cwb.googlegroups.com>

What do you mean by "use the native perl code"?

DBD/DBI is the most common and also a portable way of handling
databases.



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

Date: 09 Dec 2004 18:39:31 GMT
From: unacceptable@gmail.com (Mitchell Hulscher)
Subject: Recognize directories and files.
Message-Id: <41b89be3$0$1236$ba620dc5@nova.planet.nl>

Hey all,

Lately I've been trying to create a code that would create 2 
arrays, one containing all subdirectories in a folder and one 
containing all files in a folder. 
I'm working on a windows xp system and I've created this code:


#!C:\perl\bin\

print "Enter a full directory path to examine: ";

chomp($_ = <STDIN>);

s/\\/\//g;

$dir = $_;

opendir(HANDLE, $dir) || die "Unable to open directory for 
analysis: $!";

foreach (readdir(HANDLE)) {
   if ($_ =~ /[.*\..*]/) {
      push(@files, $_);
   } else {
      push(@dirs, $_);
   }
}

sort(@dirs, @files);

print "\n\nDirectories:\n------------\n";

foreach (@dirs) {
   print $_."\n";
}

print "\n\nFiles:\n------\n";

foreach (@files) {
   print $_."\n";
}

#End of code.

The program doesn't do anything else but adding a new item to a 
certain array if the item contains a colon, or not.
But the problem, a directory can contain colons too, which is 
very annoying.

I've also tried:

if (-d $_) {
   ...
} else {
   ...
}

Also have I tried the -f option, but none of them seem to work 
on my windows sytem. 
All items are added to the first array, so to @files if I use -
f, or to @dirs if I use -d.

If anyone has got a solution, please let me know! :)

Greetings,
Mitch.

----------------------------------------------
Posted with NewsLeecher v2.0 RC2
 * Binary Usenet Leeching Made Easy
 * http://www.newsleecher.com/?usenet
----------------------------------------------



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

Date: Thu, 09 Dec 2004 18:57:42 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Recognize directories and files.
Message-Id: <Ge1ud.1613$sU4.207@trndny01>

"Mitchell Hulscher" <unacceptable@gmail.com> wrote in message
news:41b89be3$0$1236$ba620dc5@nova.planet.nl...
> Lately I've been trying to create a code that would create 2
> arrays, one containing all subdirectories in a folder and one
> containing all files in a folder.
> I'm working on a windows xp system and I've created this code:
>
>
> #!C:\perl\bin\

You forgot
use strict;
use warnings;

Always ask for all the help you can get.
>
> print "Enter a full directory path to examine: ";
>
> chomp($_ = <STDIN>);
>
> s/\\/\//g;

Why are you doing this?

>
> $dir = $_;

Why bother making an explicit copy?  Why not just
chomp (my $dir = <STDIN>);

> opendir(HANDLE, $dir) || die "Unable to open directory for
> analysis: $!";
>
> foreach (readdir(HANDLE)) {
>    if ($_ =~ /[.*\..*]/) {

You need to read up on regular expression character classes.  The only
thing this is looking for is a single period.  If $_ contains any
period, this regexp is true.  You almost certainly don't want the [ ]
there.

Even then, if you have
if (/.*\..*/){ ... }

This is looking for "anything, followed by a period, followed by
anything."  So why aren't you just looking for the period?
if (/\./) {...}

>       push(@files, $_);
>    } else {
>       push(@dirs, $_);
>    }

Wait, so if the pattern contains a period, you assume it must therefore
be a file, and if not, it's a directory?  That's simply not true.
Directories can contain periods, and files don't need periods.

> }
>
> sort(@dirs, @files);

What exactly do you believe this is doing?  I assure you it's not doing
it.  And I'm relatively sure Perl would have told you that had you asked
for warnings.

>
> print "\n\nDirectories:\n------------\n";
>
> foreach (@dirs) {
>    print $_."\n";
> }
>
> print "\n\nFiles:\n------\n";
>
> foreach (@files) {
>    print $_."\n";
> }
>
> #End of code.
>
> The program doesn't do anything else but adding a new item to a
> certain array if the item contains a colon, or not.

Colon?   There's no colon anywhere in this code.

> But the problem, a directory can contain colons too, which is
> very annoying.

Assuming you meant "period" here, no, it's not annoying at all.  What
would be annoying is an Operating System that placed absurd restrictions
on the names of files and/or directories.

>
> I've also tried:
>
> if (-d $_) {
>    ...
> } else {
>    ...
> }
>

This is the correct method.  Looking for a period is not.

> Also have I tried the -f option, but none of them seem to work
> on my windows sytem.
> All items are added to the first array, so to @files if I use -
> f, or to @dirs if I use -d.
>
> If anyone has got a solution, please let me know! :)

The documentation for the function you're using has the solution for
you.  Have you read
perldoc -f readdir
yet?

Paul Lalli



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

Date: Thu, 09 Dec 2004 13:02:43 -0600
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: Recognize directories and files.
Message-Id: <nj1ud.21$td2.1575@news.uswest.net>

Mitchell Hulscher wrote:
> Hey all,
> 
> Lately I've been trying to create a code that would create 2 
> arrays, one containing all subdirectories in a folder and one 
> containing all files in a folder. 
[...]
> Also have I tried the -f option, but none of them seem to work 
> on my windows sytem. 
> All items are added to the first array, so to @files if I use -
> f, or to @dirs if I use -d.
> 
> If anyone has got a solution, please let me know! :)


perldoc -f readdir

Using -f and -d will work, if you test the correct item. Either chdir or 
prepending the directory.


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

Date: Thu, 09 Dec 2004 13:04:35 -0600
From: Shashank Khanvilkar <shashank@mia.ece.uic.edu>
Subject: Reg Hash of Hash
Message-Id: <cpa79v$594$1@newsx.cc.uic.edu>

Hi,
I have a program as shown below, which should print out all keys which 
have a degree of one. For example the below program should print
(e, c) = 10
since "e" has a a degree of one. But it does  not work//

$Hoh{"e"}{"c"} = 10;
$Hoh{"c"}{"f"} = 1;
$Hoh{"c"}{"d"} = 1;

foreach $n1 (keys %Hoh) {
    my $deg = keys(%{$Hoh{$n1}});
#       print "deg[$n1]  = $deg\n"; 

         if ($deg eq 1){
             $n2 = %{$aa{$n1}};
             print "($n1, $n2) = $aa{$n1}{$n2}\n";
         }
     }


However if i use the below program it works.
$Hoh{"e"}{"c"} = 10;
$Hoh{"c"}{"f"} = 1;
$Hoh{"c"}{"d"} = 1;

foreach $n1 (keys %Hoh) {
    my $deg = keys(%{$Hoh{$n1}});
#       print "deg[$n1]  = $deg\n"; 

         if ($deg eq 1){
            foreach $n2 (sort keys %{$Hoh{$n1}}) {       	
             print "($n1, $n2) = $aa{$n1}{$n2}\n";
            }
         }
     }


I will appreciate if someone can correct my first program. This way, I 
will avoid using an extra for loop.

Thanks
Shashank


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

Date: Thu, 09 Dec 2004 10:09:38 -0800
From: Bill Karwin <bill@karwin.com>
Subject: Re: regular expressions problem
Message-Id: <cpa4c002f8c@enews3.newsguy.com>

Shailesh Humbad wrote:
> Trouble is, I am using regular expressions in a VBScript file, so I
> don't have any Perl support...  Even then, the page is probably not
> valid HTML. 

There are XML & HTML parsers for Microsoft languages.  You'll be much 
more successful using something like that than trying to create a custom 
regular expression.  These types of problems tend to mutate, and very 
quickly any regular expression(s) you create will not be appropriate for 
the task.  Better to use the right tool for the job.

Here's an introduction to the Microsoft XML parser, which supports 
several languages including VBScript and Perl (see? on topic! ;-)

http://www.w3schools.com/dom/dom_parser.asp

Regards,
Bill K.


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

Date: 9 Dec 2004 10:30:22 -0800
From: simon.dukes@gmail.com (Dackle)
Subject: Retrieving web pages
Message-Id: <51f6bb21.0412091030.150bd75e@posting.google.com>

Newbie question: I'm trying to retrieve general HTML web pages but
running into a few problems, which in part are probably due to the
fact that I've never used Perl modules before. I downloaded
libwww-perl and copied LWP::Simple into the Perl lib directory, but
I'm still having trouble grabbing web pages. I tried something like
this:


use LWP::Simple;
$url="www.torontostar.com";
$content= get($url);

    But I keep getting back a type 2 error saying File "internet" does
not exist. I'm using the ActiveState port of Perl on Windows XP
through the Crimson Editor. Any advice? Is there any other way to
retrieve web pages using existing Perl modules?


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

Date: Thu, 09 Dec 2004 18:49:37 +0000
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Re: Retrieving web pages
Message-Id: <pa7hr01ss41a9mvq21rl7kuunfgsj1356i@4ax.com>

On 9 Dec 2004 10:30:22 -0800, simon.dukes@gmail.com (Dackle) wrote:

>Newbie question: I'm trying to retrieve general HTML web pages but
>running into a few problems, which in part are probably due to the
>fact that I've never used Perl modules before. I downloaded
>libwww-perl and copied LWP::Simple into the Perl lib directory, but
>I'm still having trouble grabbing web pages. I tried something like
>this:
>

use strict;
use warnings;	# Always - no help in this group otherwise!!
>use LWP::Simple;
>$url="www.torontostar.com";
>$content= get($url);
>
>    But I keep getting back a type 2 error saying File "internet" does
>not exist. I'm using the ActiveState port of Perl on Windows XP
>through the Crimson Editor. Any advice? Is there any other way to
>retrieve web pages using existing Perl modules?

I don't know what is going wrong on your system (file called
"internet" doesn't sound right, somehow).  But your problem is that
you've left out the "http:".   This works on my system (Activestate
like yours); try it.

# ------------START-------------
use strict;
use warnings;

use LWP::Simple;
my $url="http://www.torontostar.com";
my $content= get($url);

print substr($content,0,50),"\n";
# --------------END-------------

Output is:
  F:\$WIP>problem.pl
  <HTML>
  <HEAD>
  <script language="Javascript" src="h

  F:\$WIP>
-- 

Henry Law       <><     Manchester, England 


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

Date: 9 Dec 2004 11:00:28 -0800
From: "Dackle" <simon.dukes@gmail.com>
Subject: Re: Retrieving web pages
Message-Id: <1102618828.502303.159680@c13g2000cwb.googlegroups.com>

OK, I'll give it a try. I think I used http:// in the URL and it didn't
work, but I'll try use strict; and use warnings;.

Henry Law wrote:
> On 9 Dec 2004 10:30:22 -0800, simon.dukes@gmail.com (Dackle) wrote:
>
> >Newbie question: I'm trying to retrieve general HTML web pages but
> >running into a few problems, which in part are probably due to the
> >fact that I've never used Perl modules before. I downloaded
> >libwww-perl and copied LWP::Simple into the Perl lib directory, but
> >I'm still having trouble grabbing web pages. I tried something like
> >this:
> >
>
> use strict;
> use warnings;	# Always - no help in this group otherwise!!
> >use LWP::Simple;
> >$url="www.torontostar.com";
> >$content= get($url);
> >
> >    But I keep getting back a type 2 error saying File "internet"
does
> >not exist. I'm using the ActiveState port of Perl on Windows XP
> >through the Crimson Editor. Any advice? Is there any other way to
> >retrieve web pages using existing Perl modules?
>
> I don't know what is going wrong on your system (file called
> "internet" doesn't sound right, somehow).  But your problem is that
> you've left out the "http:".   This works on my system (Activestate
> like yours); try it.
>
> # ------------START-------------
> use strict;
> use warnings;
>
> use LWP::Simple;
> my $url="http://www.torontostar.com";
> my $content= get($url);
>
> print substr($content,0,50),"\n";
> # --------------END-------------
>
> Output is:
>   F:\$WIP>problem.pl
>   <HTML>
>   <HEAD>
>   <script language="Javascript" src="h
> 
>   F:\$WIP>
> -- 
> 
> Henry Law       <><     Manchester, England



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

Date: Thu, 09 Dec 2004 16:41:54 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Using MIME::Lite  for multipart message - trouble with string manipulation
Message-Id: <mf%td.1191$eO5.803@trndny08>

<alamukutty@gmail.com> wrote in message
news:1102606298.518074.181700@f14g2000cwb.googlegroups.com...

> foreach my $p (param()) {
>     $body_string = print "$p = ", param($p), "\n";
> }

What exactly do you believe this is doing?  I sincerely doubt that it's
doing it.

Paul Lalli



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

Date: Thu, 09 Dec 2004 17:05:23 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Using MIME::Lite  for multipart message - trouble with string manipulation
Message-Id: <31rc20F3f77p3U1@individual.net>

alamukutty@gmail.com wrote:
> ... I get a server error.

<snip>

You need to print a content-type header and tell the server that you 
start printing the actual page before printing other stuff to STDOUT.

     print header();

> print start_html("Thank You");

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 9 Dec 2004 08:47:05 -0800
From: "AlamuKutty" <alamukutty@gmail.com>
Subject: Re: Using MIME::Lite for multipart message - trouble with string manipulation
Message-Id: <1102610825.799211.213060@z14g2000cwz.googlegroups.com>

I figured that wasnt doing what I wanted to do. I changed that part of
the code to

my $body_string = "" ;

foreach my $p (param()) {
$body_string .= sprintf("%s = %s\n", $p, param($p));
}


Now, I have another question.

Is there anyway to format this text to be HTML ? So that I get a nice
format in my e-mail

param name(inbold)  = Param value
<double spacing here>

 .... repeated?


Thanks !



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

Date: 9 Dec 2004 09:14:03 -0800
From: "AlamuKutty" <alamukutty@gmail.com>
Subject: Re: Using MIME::Lite for multipart message - trouble with string manipulation
Message-Id: <1102612443.196376.15660@z14g2000cwz.googlegroups.com>

Hi GUnnar, I'll try that. NOw... ANOTHEr question..

Having trouble with this part ..

$file_attached = param('fileattach');
$msg->attach(
Type =>'application/msword',
Path => $file_attached

);

It says file not found. I am guessing it looks in the webserver and not
in the local machine? And the PATH to the file selected is not
displayed. For instance,if I select a file "Testing.doc" from
C:/Desktop/blahblah/TEsting.doc It doesnt work ... what should i be
doing? THANKS!



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

Date: Thu, 09 Dec 2004 18:02:14 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Using MIME::Lite for multipart message - trouble with string manipulation
Message-Id: <31rekqF3f0lkqU1@individual.net>

AlamuKutty wrote:
> 
> foreach my $p (param()) {
> $body_string .= sprintf("%s = %s\n", $p, param($p));
> }
> 
> Now, I have another question.
> 
> Is there anyway to format this text to be HTML ? So that I get a nice
> format in my e-mail

HTML is not a nice format in any email message. ;-)

> param name(inbold)  = Param value
> <double spacing here>
> 
> .... repeated?

You just print the appropriate HTML stuff in addition to what you 
already have...  What's the reason why you ask?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 09 Dec 2004 18:48:05 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Using MIME::Lite for multipart message - trouble with string manipulation
Message-Id: <31rhbdF3fn34bU1@individual.net>

AlamuKutty wrote:
> Having trouble with this part ..
> 
> $file_attached = param('fileattach');
> $msg->attach(
> Type =>'application/msword',
> Path => $file_attached
> 
> );
> 
> It says file not found. I am guessing it looks in the webserver and not
> in the local machine?

That sounds plausible.

I would suggest that you split the problem in two parts.

1) You need to learn how to upload a file to the server machine.

2) You need to know how to send an email message with an attachment.

I'd suggest that you write two separate scripts to handle those things. 
Only after you have done so successfully, it's time to combine them.

As regards uploading a file, please study the CGI.pm docs about it. Note 
also that the form needs

     enctype="multipart/form-data"

in the <form> element.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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