[28225] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9589 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 10 18:05:53 2006

Date: Thu, 10 Aug 2006 15:05:07 -0700 (PDT)
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, 10 Aug 2006     Volume: 10 Number: 9589

Today's topics:
    Re: Control characters - regex to match/lose these? <benmorrow@tiscali.co.uk>
    Re: counting number of uniques in a multidimensional ar <tzz@lifelogs.com>
    Re: counting number of uniques in a multidimensional ar <1usa@llenroc.ude.invalid>
    Re: How to send command line options into test scripts? <yusufm@gmail.com>
    Re: How to send command line options into test scripts? <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: How to send command line options into test scripts? <tadmc@augustmail.com>
    Re: How to send command line options into test scripts? <mgarrish@gmail.com>
    Re: How to send command line options into test scripts? <yusufm@gmail.com>
    Re: How to send command line options into test scripts? <yusufm@gmail.com>
    Re: Is there arithmetic sequence represents? anno4000@radom.zrz.tu-berlin.de
    Re: match 2D patterns with perl <tzz@lifelogs.com>
    Re: My code only works for 1st line in a file..need you <glennj@ncf.ca>
    Re: My code only works for 1st line in a file..need you <benmorrow@tiscali.co.uk>
    Re: My code only works for 1st line in a file..need you <Shani718@gmail.com>
    Re: My code only works for 1st line in a file..need you <syscjm@gwu.edu>
    Re: Net FTP -- Size showing different results on AIX sy usenet@DavidFilmer.com
        Perl module for SPML ? <user@example.invalid>
    Re: Read socket using both <> and sysread() xhoster@gmail.com
    Re: Read socket using both <> and sysread() <benmorrow@tiscali.co.uk>
    Re: regex and utf8 characters (german umlauts) <benmorrow@tiscali.co.uk>
    Re: Sorting integers in perl <benmorrow@tiscali.co.uk>
        The DEBUG constant? <socyl@987jk.com.invalid>
    Re: The DEBUG constant? <mritty@gmail.com>
    Re: The DEBUG constant? anno4000@radom.zrz.tu-berlin.de
    Re: win32::printer and text formatting <benmorrow@tiscali.co.uk>
    Re: win32::printer and text formatting <diavolo-verde@libero.it>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 10 Aug 2006 19:58:16 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Control characters - regex to match/lose these?
Message-Id: <87csq3-pd7.ln1@osiris.mauzo.dyndns.org>


Quoth justin.news@purestblue.com:
> On 2006-08-09, Ben Morrow <benmorrow@tiscali.co.uk> wrote:
> >
> > [re: s/\e (?: [^@A-Z]* [@A-Z] | [=9] )//gx;]
> >
> > The (?:) (when corrected) is causing the RE to match 'escape, followed
> > by (either a multi-char escape sequence or one of the single-char
> > sequences'. It is necessary as without the grouping the | alternation
> > would apply to the whole regex, and any '=' would be stripped. Compare
> 
> Thank you for clearing that up for me, I am now able to read, and
> understand, that regex. I wasn't aware of the '=' being ignored in a
> pattern match (though I'd probably escape it in most cases myself
> anyway).

No, you're misunderstanding still (I can't have been clear...). It's not
that = is ignored in a regex (it isn't), it's that without the parens
the pattern will match just '=', without a preceding escape, so all =
signs will be removed from your input. This (I presume :) ) isn't what
you want.

Ben

-- 
You poor take courage, you rich take care:
The Earth was made a common treasury for everyone to share
All things in common, all people one.                [benmorrow@tiscali.co.uk]
'We come in peace'---the order came to cut them down.


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

Date: Thu, 10 Aug 2006 14:25:39 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <g69bqqsqwgs.fsf@CN1374059D0130.kendall.corp.akamai.com>

On  9 Aug 2006, jack_posemsky@yahoo.com wrote:

> Hi Ted - great and thank you..  I tried the above and even with some
> fiddling could not get it to work..  If you know of a way to just
> capture and print out 1 example of a duplicate (not all), thats all I
> am speaking of.

Can you please post:

1) an example of your data
2) an example of the output you expect
3) what you have tried so far (and why it doesn't work)

I've given you very complete answers (I think), and don't want to keep
answering the wrong questions...

Ted


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

Date: Thu, 10 Aug 2006 20:15:32 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <Xns981BA57D7A81Easu1cornelledu@127.0.0.1>

Ted Zlatanov <tzz@lifelogs.com> wrote in 
news:g69bqqsqwgs.fsf@CN1374059D0130.kendall.corp.akamai.com:

> On  9 Aug 2006, jack_posemsky@yahoo.com wrote:
> 
 ...
>> If you know of a way to just
>> capture and print out 1 example of a duplicate (not all), thats all I
>> am speaking of.
> 
> Can you please post:
> 
> 1) an example of your data
> 2) an example of the output you expect
> 3) what you have tried so far (and why it doesn't work)
> 
> I've given you very complete answers (I think), and don't want to keep
> answering the wrong questions...

You might want to read

http://groups.google.com/group/comp.lang.perl.misc/msg/7ab0979c08ff9667

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

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: 10 Aug 2006 11:29:17 -0700
From: "yusuf" <yusufm@gmail.com>
Subject: Re: How to send command line options into test scripts?
Message-Id: <1155234557.291619.120700@p79g2000cwp.googlegroups.com>

Since people love code so much, here is an example of what I would like
to happen (if it did not error out):

test.pl:

#!/usr/bin/perl



use strict;
use warnings;



use Test::Harness;



 my @a = ('t -x HELLO');



 runtests(@a);

t:
#!/usr/bin/perl



use strict;
use warnings;



use Test::More tests => 1;



use Getopt::Std;



my %opts;



getopts('x:',\%opts);



print "X";
print $opts{x};


             
ok(1);



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

Date: Thu, 10 Aug 2006 19:20:39 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: How to send command line options into test scripts?
Message-Id: <bGLCg.2519$Qf.1525@newsread2.news.pas.earthlink.net>

On 08/10/2006 12:43 PM, yusuf wrote:
 > Mumia W. wrote:
>> Then create stub scripts that supply the correct parameters.
> 
> But wouldn't the stub scripts have to still be called by runtests()? 
> The whole issue is how to call the test files from runtests(), and 
> still pass in parameters. Even if I have stub scripts how will I send 
> in the parameters to the stub scripts, because the pid being sent in 
> will survive over multiple tests.
> 

The stub scripts contain the parameters needed by the 
executable you're testing. Each stub script will contain 
/different/ parameters.

And please don't snip attributions.


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

Date: Thu, 10 Aug 2006 14:40:22 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to send command line options into test scripts?
Message-Id: <slrnedn2t6.hn.tadmc@magna.augustmail.com>

yusuf <yusufm@gmail.com> wrote:

> Since people love code so much, 


So long!


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


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

Date: 10 Aug 2006 14:08:49 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: How to send command line options into test scripts?
Message-Id: <1155244129.252726.199970@h48g2000cwc.googlegroups.com>


yusuf wrote:

> Since people love code so much, here is an example of what I would like
> to happen (if it did not error out):
>

And here I was thinking you were an obnoxious prick at the beginning of
the thread. Way to up the ante.

Matt



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

Date: 10 Aug 2006 14:16:38 -0700
From: "yusuf" <yusufm@gmail.com>
Subject: Re: How to send command line options into test scripts?
Message-Id: <1155244597.941980.10490@75g2000cwc.googlegroups.com>


> And here I was thinking you were an obnoxious prick at the beginning of
> the thread. Way to up the ante.

What the heck is your problem? I have been providing everything that
people requested. Instead of help, I've gotten stupid comments. If you
don't want to help just shut up and move along.



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

Date: 10 Aug 2006 14:27:16 -0700
From: "yusuf" <yusufm@gmail.com>
Subject: Re: How to send command line options into test scripts?
Message-Id: <1155245236.272322.83500@74g2000cwt.googlegroups.com>

= 
> So long!

Why are you so rude? Not like you helped any.



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

Date: 10 Aug 2006 19:38:20 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Is there arithmetic sequence represents?
Message-Id: <4k1g9cFa5vlfU1@news.dfncis.de>

Ted Zlatanov  <tzz@lifelogs.com> wrote in comp.lang.perl.misc:
> On  9 Aug 2006, zhushenli@gmail.com wrote:
> 
> Tony Curtis wrote:
> >> You could find a solution with a map...
> >>
> >> map {$_ * 2} (1 .. 6);
> >>
> > [snip]
> 
> > But it seems not intuitive like [2:2:12]. Anyhow, thanks!
> 
> Write your own function:
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> use Data::Dumper;
> 
> sub matlab_list
> {
>  my $start = shift @_;

"shift @_" is the same as just "shift", which is much more common in
this function.

>  my $increment = shift @_;
>  my $end = shift @_;

If you have many arguments to pass (three is many), most people
would write that:

my ( $start, $increment, $end) = @_;

>  my @ret;
> 
>  while ($start <= $end)
>  {
>   push @ret, $start;
>   $start += $increment;
>  }
> 
>  return @ret;
> }
> 
> print "$_\n" foreach matlab_list(2, 2, 12);

There's nothing wrong with your function, but it's awfully roundabout.
Apart from the argument-passing, you failed to follow Tony Curtis'
advice (still preserved near the beginning) to use map for list
generation.  Your loop can be replaced with a little arithmetic
and a map:

    sub matlab_list {
        my ( $start, $inc, $end) = @_;
        map $start + $inc*$_, 0 .. ($end - $start)/$inc;
    }

Anno


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

Date: Thu, 10 Aug 2006 14:20:00 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: match 2D patterns with perl
Message-Id: <g69irl0qwq7.fsf@CN1374059D0130.kendall.corp.akamai.com>

On  9 Aug 2006, fangqq@gmail.com wrote:

> I am doing a very interesting work. The altimate goal is to generate a
> new style of bitmap font from an existing one. This involves finding
> and replacing 2D patterns.

Having actually done bitmap font scaling by hand, I can promise you
this is much harder than you think.  It's probably easier and cheaper
to have a human scale the glyphs from the start, and you'll get much
better results.  The reason is that you're limited to two colors and
very few pixels, and you have to make each shape recognizable and
readable.

Ted


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

Date: 10 Aug 2006 18:20:53 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: My code only works for 1st line in a file..need your help
Message-Id: <slrnedmu85.6cv.glennj@smeagol.ncf.ca>

At 2006-08-10 01:52PM, Shan <Shani718@gmail.com> wrote:
>  The follwing is the message i Get when the read file conatins more than
>  one url
>  
>  %shttp://21stcmb.typepad.com
>  Could not get the information you wanted at getfeeds2.pl line 14,
> <INFILE> line
>  1.
>  
>  
>  here is the new code (works with one url in the file)
>  -----------------------------------------------------------------------------------------------------
>  #!/usr/bin/perl -w
>  # Gets feeds
>  
>  use strict;
>  
>  
>  use LWP::Simple;
>  
>  open  (OUT,">results.txt") or die "err";
>  open(INFILE,"< urls1.txt");
>  while (<INFILE>)
>  {
>  	print("%s",$_);
>  	my $html = get("$_")
>    	or die "Could not get the information you wanted";

If you want to keep processing urls, you shouldn't die.

        my $html = get($_) or do {
            warn "Could not...";
            next;
        }

-- 
Glenn Jackman
Ulterior Designer


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

Date: Thu, 10 Aug 2006 19:40:53 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: My code only works for 1st line in a file..need your help
Message-Id: <l6bsq3-pd7.ln1@osiris.mauzo.dyndns.org>


Quoth "Shan" <Shani718@gmail.com>:
> The follwing is the message i Get when the read file conatins more than
> one url
> 
> %shttp://21stcmb.typepad.com
> Could not get the information you wanted at getfeeds2.pl line 14,
> <INFILE> line
> 1.
> 
> 
> here is the new code (works with one url in the file)
> -----------------------------------------------------

[lines this long are not really welcome on Usenet; they really don't add
to the clarity of your message]

> #!/usr/bin/perl -w

-w is for very old perls. Nowadays you should use

    use warnings;

instead.

> # Gets feeds
> 
> use strict;

Good.

> use LWP::Simple;
> 
> open  (OUT,">results.txt") or die "err";

Ignoring what people say is not considered polite. Paul has already told
you (for good reason) to write this as

    open(my $OUT, '>', 'results.txt') 
        or die "can't write to 'results.txt': $!"

I've kept your parens even though I (and most people here) wouldn't use
them as they are often helpful to people who are unsure of Perl's
precedence table (which is complicated, so that's OK :) ).

> open(INFILE,"< urls1.txt");

As above.

FWIW, it's usually better not to hardcode filenames. Either use
something like Getopt::Std to let your program accept sensible
arguments, or in this case I'd probably just use <> and print to STDOUT.
Then you invoke your program like

    C:\whatever\> perl checkfeeds.pl urls1.txt > results.txt

(I'm assuming since you're using .txt extensions that you're on Win32.
If not adjust appropriately.)

> while (<INFILE>)
> {
> 	print("%s",$_);

print ne printf. Read the documentation for the functions you use:
perldoc -f print.

You haven't set $\, so this will print all the urls jammed up together
(or would, if you didn't have a useless "%s" in there).

Diagnostic output should generally go to STDERR, or if (as I suspect)
this is just for debugging, should use warn.

    print STDERR $_;

or

    warn "Trying to get url '$_'";

> 	my $html = get("$_")

Don't quote variables when you don't need to. Did you read Paul's reply?
You are still trying to GET a url with a newline on the end: I strongly
suspect that since "\n" is not a valid character in URLs LWP is DWYM,
but you should still say what you mean. Read perldoc -f chomp or read
about the -l flag in perldoc perlrun. I would also use the -n flag here,
but you may find it easier to be explicit.

>   	or die "Could not get the information you wanted";

A more informative error message would be useful. As would be not
abandoning the whole program when one URL fails; something like

    URL: while (<INFILE>) {

        ...

        my $html = get $_;
        unless (defined $html) {
            warn "Can't GET '$_'";
            next URL;
        }

        ...
    }

Unfortunately the LWP::Simple::get function doesn't allow you to get at
the error code... it may be worth rewriting to use the proper
LWP::UserAgent interface if you have persistant problems with some URLs.

> 	while ($html =~ m{<link rel="alternate"(.*?) />}g)

You really *never* want to parse X?HTML with a regexp. Use a proper
module; I'm not sure what I'd use in this case: any recommendations
anyone?

Ben

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                         benmorrow@tiscali.co.uk


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

Date: 10 Aug 2006 13:41:52 -0700
From: "Shan" <Shani718@gmail.com>
Subject: Re: My code only works for 1st line in a file..need your help
Message-Id: <1155242511.959032.294690@p79g2000cwp.googlegroups.com>

Thank you all. I added chop and now everythign is working



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

Date: Thu, 10 Aug 2006 17:24:47 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: My code only works for 1st line in a file..need your help
Message-Id: <12dn912mcf8t87c@corp.supernews.com>

Shan wrote:
> Thank you all. I added chop and now everythign is working
> 

Use chomp, not chop.


Chris Mattern


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

Date: 10 Aug 2006 14:43:33 -0700
From: usenet@DavidFilmer.com
Subject: Re: Net FTP -- Size showing different results on AIX system and Linux system
Message-Id: <1155246213.523978.114120@b28g2000cwb.googlegroups.com>

fmbright wrote:
> I get the correct filesizes when I do an ftp from both boxes.  And when
> I do a windows FTP to the site.

I believe folks are still waiting for your small complete sample
program which illustrates your problem (similar to the example that
Simon kindly posted).

I don't think you have yet grasped the importance of this aspect of
asking a good question.  Allow me to demonstrate...

I was recently having problems working with a server (a news server,
not an FTP server, but that doesn't really matter).  My "problem
program" is hundreds of lines long with lots of comments and debugging.
But take a look at the question I posted:

    http://tinyurl.com/mw9jh
or  <1155082296.203967.290390@75g2000cwc.googlegroups.com>

Notice a SHORT (only a dozen lines) but COMPLETE example of the
specific problem I was having which anyone in usenet could
cut-and-paste into their editor and try it out. And, whadda ya know,
somebody did!

Notice that about an hour later, a responder had kindly identified the
source of the problem, and about an hour after that he kindly furnished
code which illustrated and corrected my problem.  We had further
productive conversation where I learned some more about the module I
was using (including some methods that aren't in the perldocs).

In less than three hours, I knew EXACTLY what was wrong and EXACTLY how
to fix it.  That's because I got a good answer.  One of the most
important reasons why I got a good answer was because I asked a good
question.  I closely conformed to the CLPMisc posting guidelines and I
got polite, fast, and expert help.

I got a good answer in three HOURS. You still have not gotten a good
answer after three DAYS.  That's because you STILL have not asked a
good question.  We have described the task; we have pointed you to the
guidelines; we have given you a nearly-complete example.  We have TRIED
to show you how to ask a good question but you persist in ignoring our
advice.

The only person that harms is you.

-- 
David Filmer (http://DavidFilmer.com)



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

Date: Thu, 10 Aug 2006 11:39:33 -0700
From: "J. Fowler" <user@example.invalid>
Subject: Perl module for SPML ?
Message-Id: <76LCg.369$B4.847013@nntp.csufresno.edu>

Are there any known Perl modules implementing the Service Provisioning 
Markup Language (SPML) protocol?

http://www.openspml.org/


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

Date: 10 Aug 2006 18:16:00 GMT
From: xhoster@gmail.com
Subject: Re: Read socket using both <> and sysread()
Message-Id: <20060810142535.586$hg@newsreader.com>

Uri Guttman <uri@stemsystems.com> wrote:
>
>   x> Is the fact that read will block until the requested size (or eof)
>   x> is read (as opposed to sysread, which blocks until at least 1 byte
>   x> is read, but after that will return a partial buffer if need be
>   x> rather than blocking) a real feature or a malfeature or a bug?
>
> read will restart if it was interrupted by a signal and sysread will
> return a partial read or some EINTR error instead.
>
> sysread will block on its read size unless you set the socket to
> non-blocking mode.

That doesn't seem to be the case in my hands.
My localhost:9871 server now prints 100 bytes to the socket every 8
seconds.

> perl -le 'use IO::Socket;
            my $x=IO::Socket::INET->new("localhost:9871") or die $@;
            $SIG{ALRM}=sub{alarm 5}; alarm 5;
            print sysread ($x,$buf,75), q": $! is:", $! foreach 1..1000;
           '
75: $! is:
25: $! is:
: $! is:Interrupted system call
75: $! is:
25: $! is:
: $! is:Interrupted system call
: $! is:Interrupted system call
75: $! is:
25: $! is:

The first 75 and 25 bytes reads are instant (the 75 because that is what
you asked for, the 25 because that is all that is left of the 100 printed
by the other end), then a 5 second pause until the alarm times out giving
us the interupted system call, then 3 seconds until the next 75 and 25
reads. So it will only block on the first byte, not for the full read size.

Of course by turning on non-blocking mode by using O_NONBLOCK, then it
doesn't block even for the first byte.

Xho

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


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

Date: Thu, 10 Aug 2006 20:36:10 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Read socket using both <> and sysread()
Message-Id: <aeesq3-h68.ln1@osiris.mauzo.dyndns.org>


Quoth xhoster@gmail.com:
> Uri Guttman <uri@stemsystems.com> wrote:
> >
> >   x> Is the fact that read will block until the requested size (or eof)
> >   x> is read (as opposed to sysread, which blocks until at least 1 byte
> >   x> is read, but after that will return a partial buffer if need be
> >   x> rather than blocking) a real feature or a malfeature or a bug?
> >
> > read will restart if it was interrupted by a signal and sysread will
> > return a partial read or some EINTR error instead.
> >
> > sysread will block on its read size unless you set the socket to
> > non-blocking mode.
> 
> That doesn't seem to be the case in my hands.
>
<snip example>
> The first 75 and 25 bytes reads are instant (the 75 because that is what
> you asked for, the 25 because that is all that is left of the 100 printed
> by the other end), then a 5 second pause until the alarm times out giving
> us the interupted system call, then 3 seconds until the next 75 and 25
> reads. So it will only block on the first byte, not for the full read size.

Yes. That is what read(2) (and SUS) says it does. If you want reliable
behaviour you want to use O_NONBLOCK and select/poll anyway, and deal
with EINTR.

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 'Alcestis')        [ flame, and falls out of sight. ]  benmorrow@tiscali.co.uk


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

Date: Thu, 10 Aug 2006 20:31:56 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: regex and utf8 characters (german umlauts)
Message-Id: <c6esq3-h68.ln1@osiris.mauzo.dyndns.org>


Posting 8bit data on Usenet is not a good idea. There is no way of
indicating its encoding. In what appears below, I have replaced the
literal byte "\xc4" with "<c4>", and re-wrapped the result.

Quoth Ted Zlatanov <tzz@lifelogs.com>:
> On 10 Aug 2006, ext-dirk.heinrichs@nokia.com wrote:
> 
> > the following little perl snippet
> >
> > perl -e '($string = "AAA <c4><c4><c4> BBB CCC DDD") =~
> > s/(\p{IsUpper}+)/\L\u\1\E/g; print $string . "\n"'
                         ^^
This is a sed-ism. In Perl backreferences (outside of the pattern
itself) are spelt $1.

Also, I would consider it much clearer to write this as

    s/(\p{IsUpper}+)/ucfirst lc $1/ge;

> > gives this result:
> >
> > Aaa <c4><c4><c4> Bbb Ccc Ddd
> >
> > How do I turn those umlauts into "<c4><e4><e4>" also? I tried adding
> > "use utf8;", but that didn't help.
> 
> The utf8 pragma won't make a difference.  <e4> is ASCII code 196.

There is No Such Thing as 'ASCII code 196'. ASCII only goes up to 127.

As the post arrived here, the section of code represented above by
'<c4><c4><c4>' is 3 bytes long. This is not valid UTF8, so if these
three bytes are actually in your file you have a problem. I suspect your
file is actually encoded in ISO8859-1; you can tell Perl this by putting

    use encoding 'iso8859-1';

before any 8bit bytes occur. You may also want to tell Perl what
encoding you expect the output in; for this you need to use the
:encoding() PerlIO layer.

The behaviour of perl's builtins on strings containing bytes \x80-\xff
but which don't have the internal utf8 flag set can be somewhat weird.
This is the result of perl trying to reconcile the (basically
irreconcilable (sp?)) conditions of behaving properly Unicode-y if you
use Unicode and behaving the same as 5.6 used to if you don't. If you
always stick to properly en/decoding your data (with the encoding
pragma, the :encoding() layer and Encode::{en,de}code) you should be OK.

You probably also want to avoid using non-ascii chars from the shell.
What your terminal/shell do with the data is distinctly unpredictable.

Ben

-- 
  Razors pain you / Rivers are damp
  Acids stain you / And drugs cause cramp.                    [Dorothy Parker]
  Guns aren't lawful / Nooses give
  Gas smells awful / You might as well live.            benmorrow@tiscali.co.uk


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

Date: Thu, 10 Aug 2006 19:52:57 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Sorting integers in perl
Message-Id: <9tbsq3-pd7.ln1@osiris.mauzo.dyndns.org>


[quoting fixed: don't do that]

Quoth gkarpo@gmail.com:
> praveen.kantharajapura@gmail.com wrote:
> >
> > I have a file which contains characters as well as integers.
> > Now i should sort all the integers ??
> > How to go about doing it.
> 
> sort() should do, but it defaults to sorting in string mode.
> You would need to switch to numeric mode: sort { $a <=> $b } @list

At the risk of sounding like Uri :), you probably want to use his
Sort::Maker module for sorting. It makes it much easier to get things
right, as well as being (in some cases) much faster.

Ben

-- 
And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
                       * benmorrow@tiscali.co.uk *


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

Date: Thu, 10 Aug 2006 18:40:07 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: The DEBUG constant?
Message-Id: <ebfui7$qf9$1@reader2.panix.com>




In perl documentation, I often run into references to a "DEBUG
constant", or some such.  E.g., in the documentation for Carp::Assert
one sees code like this:

  assert(EXPR) if DEBUG;

Is there in fact a special DEBUG constant in Perl, or does code
like the example above simply imply that elsewhere in the current
package one has a line like

  use constant DEBUG => 0;

?

The above definition of DEBUG through the constant pragma is
straighforward enough but, as far as I can tell, it has the major
disadvantage of requiring the editing of the code to toggle its
value (as opposed to being easily settable from the command-line,
or perhaps from a config file), since all too often programmers
like me will forget to re-edit the code to ensure that DEBUG is
false in production code.  Is this assessment correct?

Thanks!

kj
-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.


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

Date: 10 Aug 2006 11:46:21 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: The DEBUG constant?
Message-Id: <1155235581.002339.126510@m79g2000cwm.googlegroups.com>

kj wrote:
> In perl documentation, I often run into references to a "DEBUG
> constant", or some such.  E.g., in the documentation for Carp::Assert
> one sees code like this:
>
>   assert(EXPR) if DEBUG;
>
> Is there in fact a special DEBUG constant in Perl, or does code
> like the example above simply imply that elsewhere in the current
> package one has a line like
>
>   use constant DEBUG => 0;
>
> ?

That is my take on it, yes.

> The above definition of DEBUG through the constant pragma is
> straighforward enough but, as far as I can tell, it has the major
> disadvantage of requiring the editing of the code to toggle its
> value (as opposed to being easily settable from the command-line,
> or perhaps from a config file), since all too often programmers
> like me will forget to re-edit the code to ensure that DEBUG is
> false in production code.  Is this assessment correct?

Yes.

I tend to use Getopt::Long when I want to enable or disable debug
statements....

use Getopt::Long;
GetOptions('debug' => \my $DEBUG);

assert($foo eq $bar) if $DEBUG;

__END__

And then on the command line...

 ./assertions.pl --debug
or even just
 ./assertions.pl -d

Paul Lalli



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

Date: 10 Aug 2006 19:56:19 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: The DEBUG constant?
Message-Id: <4k1hb3Fa7queU1@news.dfncis.de>

Paul Lalli <mritty@gmail.com> wrote in comp.lang.perl.misc:
> kj wrote:
> > In perl documentation, I often run into references to a "DEBUG
> > constant", or some such.  E.g., in the documentation for Carp::Assert
> > one sees code like this:
> >
> >   assert(EXPR) if DEBUG;
> >
> > Is there in fact a special DEBUG constant in Perl, or does code
> > like the example above simply imply that elsewhere in the current
> > package one has a line like
> >
> >   use constant DEBUG => 0;
> >
> > ?
> 
> That is my take on it, yes.
> 
> > The above definition of DEBUG through the constant pragma is
> > straighforward enough but, as far as I can tell, it has the major
> > disadvantage of requiring the editing of the code to toggle its
> > value (as opposed to being easily settable from the command-line,
> > or perhaps from a config file), since all too often programmers
> > like me will forget to re-edit the code to ensure that DEBUG is
> > false in production code.  Is this assessment correct?
> 
> Yes.

To the OP: You can add unconditional debugging output to remind yourself
to switch off debugging, for instance (untested)

    END { warn "Debugging active" if DEBUG }

There may be a form of assertion that can be used instead of warn().

Perl will go out of its way to execute an END block, so you'll
always see the final warning while debugging is on.  An uncaught
exception is the only way to bypass END.  There is little danger
of accidentally releasing software in that state.

> I tend to use Getopt::Long when I want to enable or disable debug
> statements....
> 
> use Getopt::Long;
> GetOptions('debug' => \my $DEBUG);
> 
> assert($foo eq $bar) if $DEBUG;
> 
> __END__
> 
> And then on the command line...
> 
> ./assertions.pl --debug
> or even just
> ./assertions.pl -d

One point about the the approach using constants is that a statement
qualified by "if DEBUG" will not even be compiled when debugging
is off.  Thus code with "DEBUG => 0" will be the same as if no
assertions were present at all.

Anno


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

Date: Thu, 10 Aug 2006 19:45:19 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: win32::printer and text formatting
Message-Id: <vebsq3-pd7.ln1@osiris.mauzo.dyndns.org>


Quoth "diavolo-verde@libero.it" <diavolo-verde@libero.it>:
> Hello,
> 
> I use Win32::printer for my prints. I print just simple text, i.e.
> 
>     $rowHeight = $dc->Write($description, $x, $y);
>     $x += 45;
>     $rowHeight = $dc->Write($arrivalDate, $x, $y);
>     $x += 20;
>     $rowHeight = $dc->Write($price, $x, $y);
>     $y += $rowHeight;
> 
> I'd like to print the currency right formatted:
> 204,00
>  12,10
> 
> I didn't undersand very much the win32::printer manual on CPAN. Would
> anyone give me an example how to do it?

You need to use either sprintf or POSIX::localeconv or I18N::Langinfo;
or possibly there is a CPAN module to make this easier (the POSIX locale
interface is rather smelly).

Ben

-- 
   If you put all the prophets,   |   You'd have so much more reason
   Mystics and saints             |   Than ever was born
   In one room together,          |   Out of all of the conflicts of time.
benmorrow@tiscali.co.uk                             The Levellers, 'Believers'


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

Date: 10 Aug 2006 14:58:09 -0700
From: "diavolo-verde@libero.it" <diavolo-verde@libero.it>
Subject: Re: win32::printer and text formatting
Message-Id: <1155247089.654247.165470@h48g2000cwc.googlegroups.com>


Ben Morrow ha scritto:

> You need to use either sprintf or POSIX::localeconv or I18N::Langinfo;
> or possibly there is a CPAN module to make this easier (the POSIX locale
> interface is rather smelly).

Thanks Ben, I don't understand. I thought I could use
win32::printer::write or write2 with their options:

  # String mode (SM):
  $height = $dc->Write($text, $x, $y, [$format, [$just_width]]);
  ($width, $height) = $dc->Write($text, $x, $y, [$format,
[$just_width]]);

  # Draw mode (DM):
  $height = $dc->Write($text, $x, $y, $width, $height, [$format,
[$tab_stop]]);
  ($width, $height, $length, $text) = $dc->Write($text, $x, $y, $width,
$height, [$format, [$tab_stop]]);

but I can't figure out how to use them. How sprintf could help me
printing on printer device?

Thanks,

Davide



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

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


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