[23691] in Perl-Users-Digest
Perl-Users Digest, Issue: 5898 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 5 14:05:54 2003
Date: Fri, 5 Dec 2003 11:05:14 -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 Fri, 5 Dec 2003 Volume: 10 Number: 5898
Today's topics:
Re: any idea how to optimize this regex? <flavell@ph.gla.ac.uk>
Getting return code from a child process (Jon)
Re: gui in perl <HelgiBriem_1@hotmail.com>
Re: gui in perl <usenet@morrow.me.uk>
Re: gui in perl <ubl@schaffhausen.de>
Re: gui in perl <zentara@highstream.net>
Re: gui in perl <bik.mido@tiscalinet.it>
Re: gui in perl (laszlo)
Re: How to open a file from the end and read the last 1 (Tad McClellan)
Re: How to open a file from the end and read the last 1 (Sara)
Re: Idiom for array index that I'm foreach'ing over? (Tim Shoppa)
Re: Idiom for array index that I'm foreach'ing over? <bmb@ginger.libs.uga.edu>
Re: Idiom for array index that I'm foreach'ing over? <bik.mido@tiscalinet.it>
Re: Idiom for array index that I'm foreach'ing over? (Anno Siegel)
Re: Idiom for array index that I'm foreach'ing over? <usenet@morrow.me.uk>
Re: Idiom for array index that I'm foreach'ing over? <bmb@ginger.libs.uga.edu>
Re: Idiom for array index that I'm foreach'ing over? <bmb@ginger.libs.uga.edu>
printf question <blank@blank.blank.com>
Re: printf question <tony_curtis32@_SPAMTRAP_yahoo.com>
Re: printf question <blank@blank.blank.com>
Re: printf question <simon.andrews@bbsrc.ac.uk>
Re: printf question <blank@blank.blank.com>
Printing raw characters? (Eduardo)
Re: Printing raw characters? <usenet@morrow.me.uk>
read file & check input with regex <chatasos@yahoo.com>
Re: read file & check input with regex <usenet@morrow.me.uk>
Re: read file & check input with regex <nobull@mail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 5 Dec 2003 16:19:01 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: any idea how to optimize this regex?
Message-Id: <Pine.LNX.4.53.0312051616320.25622@ppepc56.ph.gla.ac.uk>
On Fri, 5 Dec 2003, Matt Garrish wrote:
> I thought no whitespace at the start of a comment was one of the few things
> that html did enforce?
This is wildly off-topic, but one of the things I had to learn about
HTML is that even the W3C HTML specs contain self-contradictions.
While claiming in one place to be an application of SGML, there are
other places where particular SGML constructs are prohibited which the
SGML specification does not allow to be prohibited.
> Then again, what standards do any browsers adhere to? : )
That's another matter entirely. And just don't start me on Appendix C
to XHTML/1.0
------------------------------
Date: 5 Dec 2003 10:24:15 -0800
From: jhayden@usa.com (Jon)
Subject: Getting return code from a child process
Message-Id: <28769dad.0312051024.790055a7@posting.google.com>
How do I get the return value of a child process? Take this example:
====================================
sub my_function {
return 10;
}
my $return=0;
my $child_pid=0;
if (!defined($child_pid = fork())) {
die "cannot fork: $!";
} elsif ($child_pid) {
# I'm the parent
} else {
# I'm the child
$return = my_function();
print("return is $return\n");
exit 0;
}
my $pid = wait;
print("return is $return\n")
==========================================
Output is:
return is 10
return is 0
The wait() function returns the pid and what I really want is the
return code from that pid. I would like to pass the return code of a
function I ran in the child back to the parent...Is there a simple way
to do this? I *think* there might be a way to do this with pipes, but
I have no clue as to how to do that.
Thanks for any help,
Jon
------------------------------
Date: Fri, 05 Dec 2003 14:07:38 +0000
From: Helgi Briem <HelgiBriem_1@hotmail.com>
Subject: Re: gui in perl
Message-Id: <u141tvsp87amc1ftcekkqi23asotslbe32@4ax.com>
On Fri, 5 Dec 2003 08:40:02 -0500, "Matt Garrish"
<matthew.garrish@sympatico.ca> wrote:
>But is it worth the pain? I've given up on Tk and just use vc++ to build gui
>wrappers to my perl scripts (when I'm too lazy to rewrite all my code in
>vc++ but have to make a program "user-friendly").
You find VC++ easier than Tk?!?!
You've been doing something wrong, that's for sure.
------------------------------
Date: Fri, 5 Dec 2003 15:06:20 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: gui in perl
Message-Id: <bqq6tc$a3k$1@wisteria.csv.warwick.ac.uk>
Helgi Briem <HelgiBriem_1@hotmail.com> wrote:
> On Fri, 5 Dec 2003 13:20:55 +0000 (UTC), Ben Morrow
> <usenet@morrow.me.uk> wrote:
>
> >scriptyrich@yahoo.co.uk wrote:
> >> As others have said, there is also the Tk stuff - certainly pretty easy to
> >> use and get up and running, but from my experience it produces horrible
> >> looking apps - but that may not be of concern to you, and I know the Tk
> >> guys are working on it.
> >
> >While this is certainly true under Unix, the win32 port of Tk produces
> >apps which look just like any other windows app; no more and no less
> >offensive :).
>
> It looks just as good (or bad) as the underlying windowing
> system, X, Apple Mac or whatever.
X, unlike win32 and MacOS, does not define a widget set. Tk uses its
own, which is different from any other, and (IMHO) is truly hideous.
> It certainly always looks better than anything produced by Java and
> it's far, far easier to program. My god, Java produces horrible
> looking guis.
Yes. :) I'm hoping the GCJ folks are going to implement Swing in terms
of Gtk...
Ben
--
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
-Assyrian stone tablet, c.2800 BC ben@morrow.me.uk
------------------------------
Date: Fri, 05 Dec 2003 16:15:42 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: gui in perl
Message-Id: <bqqah6$ig7$1@news.dtag.de>
Helgi Briem wrote:
>>>As others have said, there is also the Tk stuff - certainly pretty easy to
>>>use and get up and running, but from my experience it produces horrible
>>>looking apps - but that may not be of concern to you, and I know the Tk
>>>guys are working on it.
>>
>>While this is certainly true under Unix, the win32 port of Tk produces
>>apps which look just like any other windows app; no more and no less
>>offensive :).
>
>
> It looks just as good (or bad) as the underlying windowing
> system, X, Apple Mac or whatever. It certainly always
> looks better than anything produced by Java and it's far,
> far easier to program. My god, Java produces horrible looking
> guis.
Thats Swing, not Java. AWD (right acronym?) used by e.g. Eclipse is
really beautiful.
malte
------------------------------
Date: Fri, 05 Dec 2003 10:38:23 -0500
From: zentara <zentara@highstream.net>
Subject: Re: gui in perl
Message-Id: <eb91tv0bkh8lukd5mne2mgkvj91qmhrpkj@4ax.com>
On Fri, 5 Dec 2003 13:20:55 +0000 (UTC), Ben Morrow
<usenet@morrow.me.uk> wrote:
>
>scriptyrich@yahoo.co.uk wrote:
>> As others have said, there is also the Tk stuff - certainly pretty easy to
>> use and get up and running, but from my experience it produces horrible
>> looking apps - but that may not be of concern to you, and I know the Tk
>> guys are working on it.
>
>While this is certainly true under Unix, the win32 port of Tk produces
>apps which look just like any other windows app; no more and no less
>offensive :).
And in linux, you can design your Tk app on a Tk::Canvas or a Tk::Zinc
canvas, and make it look as cool as you want. You can have fancy bitmap
backgrounds with animated buttons and zooming.
--
When life conspires against you, and no longer floats your boat,
Don't waste your time with crying, just get on your back and float.
------------------------------
Date: 5 Dec 2003 16:37:38 GMT
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: gui in perl
Message-Id: <ebodtv0kap1s9evdd3l3i3gm9mq2hpg28s@4ax.com>
On Fri, 05 Dec 2003 08:48:39 +1100, Edo <eddGallary2@hotmail.com>
wrote:
>Hello
>
>I need to know if perl is ok for an interactive gui programming,
>
>e.g. tasks I need to do are:
[snip]
use Tk;
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: 5 Dec 2003 09:06:56 -0800
From: GlgAs@Netscape.net (laszlo)
Subject: Re: gui in perl
Message-Id: <945e4584.0312050906.e1fc80f@posting.google.com>
Edo <eddGallary2@hotmail.com> wrote in message news:<3FCFABB7.70507@hotmail.com>...
> Hello
>
> I need to know if perl is ok for an interactive gui programming,
>
> e.g. tasks I need to do are:
If you wanna write satand alone programs use Java, or pert with Tk
module. The advantege of the perl is the significantly less owerhead,
and the superior string processing capability, the advantege of the
Java is the more superior user interface capability
If you wanna write CGI scripts w/ interactive webpages, you may use
perl w/ some limitations w/o special modules
- use a form on the desktop to run a perl script by mouse click, let
perl
script variables use values from text boxes
This is what CGI-perl does primarily.
- create a chart with mouse location indicated when moved on the x and
y axis.
I would use javascript to save and show the mouseclicks, then (after
finishing ) perl script to show the lines from the vector posted by
the javascript
- add scroll function to a chart,
with the browsers this is automatic
- automate chart scale,
you can write lines (w/ any calculated scaling) simply generating
null images with STYLE parameters which set the sizes and the
background color. Bars or axias paralel lines are one image, not
axis paralell lines could be generated dotwise, by my experience 5000
images per webpage are still work with acceptable speed
- display data from files on a spread sheet
For active spread sheet (on webpage) you may use javascript w/ quite
easily, perl could set up a set of text input gadgets
------------------------------
Date: Fri, 5 Dec 2003 09:02:51 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to open a file from the end and read the last 100 lines
Message-Id: <slrnbt17gr.7qc.tadmc@magna.augustmail.com>
Ingo Menger <quetzalcotl@consultant.com> wrote:
> If you don't have tail, you'll also want to replace your OS.
That would be the best optimization.
But "half a loaf is better than none", so the unfortunates can get
tail for their dain-bramaged OS:
http://www.perl.com/language/ppt/src/tail/index.html
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 5 Dec 2003 10:46:42 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: How to open a file from the end and read the last 100 lines
Message-Id: <776e0325.0312051046.540df637@posting.google.com>
rui.vilao@rocketmail.com (Rui Vilao) wrote in message news:<385a715f.0312041004.71e2d777@posting.google.com>...
> Greetings,
>
> I am writing some Perl script to check some patterns errors in an
> alert log (Oracle alert log). The file can't get quite large.
> Therefore I would like write a Perl script that runs every day via at
> and opens the file from the end to read the last 100 lines. How can I
> do this?
> Any help/suggestion is highly appreciated.
>
> Thanks in advance for your help,
>
> Kind Regards,
>
> Rui Vilao
Good Day Rui:
There are some modules in CPAN that would be useful - but it's more
fun to roll your own! You DO say that the file CAN'T get quite large,
which is curious because my logs DO get quite large here on thie RH8
server. But if it's small why not just:
die "I hate MONDAYS!\n" unless open F, 'log';
my @l = <F>;
close F;
@l = splice @l, @l-100;
and botta bing you have your last 100 lines!
G
------------------------------
Date: 5 Dec 2003 06:57:18 -0800
From: shoppa@trailing-edge.com (Tim Shoppa)
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <bec993c8.0312050657.7e1562ae@posting.google.com>
Tore Aursand <tore@aursand.no> wrote in message news:<pan.2003.12.04.16.16.56.509801@aursand.no>...
> On Thu, 04 Dec 2003 07:42:42 -0800, Tim Shoppa wrote:
> > Is there some magical variable like $. for array loops?
>
> No. You say that you've been programming Fortran, and you're saying - at
> the same time - that you're too lazy to write the following code?
>
> my $i = 0;
> foreach ( @array ) {
> $_ . ' at position ' . $i . "\n";
> $i++;
> }
>
> Crazy. :-)
Creating a brand new variable with scope outside the loop body and no
use outside the body, which I then have to increment each time
around the loop (and remember not to "next" before the code that increments
it), when obviously the computer internally knows the index of the
element it's working on, isn't crazy?
And while everyone is telling me that I'm some thick-headed Fortran
programmer who doesn't know how to use Perl data structures, I
generally have to generate arrays in these forms because
other Perl modules from CPAN insist on non-structured arrays of
X-Y data. (Specifically, GD::Graph and Perl/Tk, but they take their
arrays in different orders... GD::Graph wants a list of x's and a list of
y's, while Perl/Tk generally wants x0-y0-x1-y1-x2-y2-etc.). I did
learn some less-than-elegant idioms for converting to/from these forms, though.
Tim.
------------------------------
Date: Fri, 5 Dec 2003 11:24:33 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <Pine.A41.4.58.0312051120540.17518@ginger.libs.uga.edu>
On Fri, 5 Dec 2003, Tim Shoppa wrote:
> Creating a brand new variable with scope outside the loop body and no
> use outside the body, which I then have to increment each time
> around the loop (and remember not to "next" before the code that increments
> it), when obviously the computer internally knows the index of the
> element it's working on, isn't crazy?
Okay, for what it's worth, here's my attempt at cleverness. No, it's not
exactly what you asked for ...
{{
my $i=0;
sub rewind{$i=0}
sub it(\@){$i>$#{$_[0]}?():($i+0,$_[0][$i++])}
}}
while( my( $i, $it ) = it( @array ) ) {
print "i: $i, it: $it\n";
}
Regards,
Brad
------------------------------
Date: 5 Dec 2003 16:37:38 GMT
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <u6odtvg7p86nscpajm8p360ga1q8g2ta2k@4ax.com>
On Thu, 4 Dec 2003 23:10:18 -0500, Brad Baxter
<bmb@ginger.libs.uga.edu> wrote:
>Here's another. :-)
>
>{{
^^
>my $i=0;
>sub rewind{$i=0}
>sub eAch(\@\@){$i>$#{$_[0]}&&$i>$#{$_[1]}?():($_[0][$i],$_[1][$i ++])}
>}}
^^
Why double braces?!? Ah! Nice JAPH btw...
Michele
--
$\=q.,.,$_=q.print' ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;
------------------------------
Date: 5 Dec 2003 17:32:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <bqqfeu$gfr$1@mamenchi.zrz.TU-Berlin.DE>
Brad Baxter <bmb@ginger.libs.uga.edu> wrote in comp.lang.perl.misc:
> On Fri, 5 Dec 2003, Tim Shoppa wrote:
> > Creating a brand new variable with scope outside the loop body and no
> > use outside the body, which I then have to increment each time
> > around the loop (and remember not to "next" before the code that increments
> > it), when obviously the computer internally knows the index of the
> > element it's working on, isn't crazy?
>
> Okay, for what it's worth, here's my attempt at cleverness. No, it's not
> exactly what you asked for ...
>
> {{
> my $i=0;
> sub rewind{$i=0}
> sub it(\@){$i>$#{$_[0]}?():($i+0,$_[0][$i++])}
> }}
>
> while( my( $i, $it ) = it( @array ) ) {
> print "i: $i, it: $it\n";
> }
Drawing in the OPs intentions, this would be required to work for more
than one array. We can't make the number of arrays entirely arbitrary
due to limitations in prototypes (or can we?), but this works for up
to five arrays:
BEGIN {{
my $i = -1;
sub rewind { $i = -1 }
sub them (;\@\@\@\@\@) {
$i++; # increment early, so we can return a valid index
return if $i >= @{ $_[ 0]};
( $i, map $_->[ $i], @_);
}
}}
while ( my ( $i, $x, $y, $t) = them( @xx, @yy, @tt) ) {
print "i: $i, x: $x, y: $y, t: $t\n";
}
Of course this is utterly fragile when applied to more than one set
of arrays, but for the given purpose it would do.
Anno
------------------------------
Date: Fri, 5 Dec 2003 17:56:26 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <bqqgsa$j1m$1@wisteria.csv.warwick.ac.uk>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> BEGIN {{
> my $i = -1;
> sub rewind { $i = -1 }
>
> sub them (;\@\@\@\@\@) {
> $i++; # increment early, so we can return a valid index
> return if $i >= @{ $_[ 0]};
> ( $i, map $_->[ $i], @_);
> }
> }}
>
> while ( my ( $i, $x, $y, $t) = them( @xx, @yy, @tt) ) {
> print "i: $i, x: $x, y: $y, t: $t\n";
> }
>
> Of course this is utterly fragile when applied to more than one set
> of arrays, but for the given purpose it would do.
To remove some of the fragility (untested):
BEGIN {{
my %i;
sub rewind (;\@\@\@\@\@) { $i{join "", @_} = -1 }
sub them (;\@\@\@\@\@) {
my $set = join "", @_;
$i{$set} = -1 unless defined $i{$set}; # $i{$set} //= -1;
$i{$set}++;
rewind(@_), return if grep { $i{$set} >= @$_ } @_;
# I'm not sure what we want here... 'if @_ == grep ...' may be better.
( $i{$set}, map $_->[$i{$set}], @_);
}
}}
Ben
--
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk
------------------------------
Date: Fri, 5 Dec 2003 13:07:00 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <Pine.A41.4.58.0312051304540.17518@ginger.libs.uga.edu>
On Fri, 5 Dec 2003, Michele Dondi wrote:
> On Thu, 4 Dec 2003 23:10:18 -0500, Brad Baxter
> <bmb@ginger.libs.uga.edu> wrote:
>
> >{{
> ^^
> >my $i=0;
> >sub rewind{$i=0}
> >sub eAch(\@\@){$i>$#{$_[0]}&&$i>$#{$_[1]}?():($_[0][$i],$_[1][$i ++])}
> >}}
> ^^
>
> Why double braces?!? Ah! Nice JAPH btw...
Thanks. :-) The double braces are just a nod to Anno's post on Nov 22,
re: top level blocks and indentation.
Regards,
Brad
------------------------------
Date: Fri, 5 Dec 2003 13:30:30 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <Pine.A41.4.58.0312051040450.17518@ginger.libs.uga.edu>
On Fri, 5 Dec 2003, Anno Siegel wrote:
> Brad Baxter <bmb@ginger.libs.uga.edu> wrote in comp.lang.perl.misc:
> > Here's one non-destructive version:
> >
> > my %h;
> > @h{@xx}=@yy;
> > for ( map [ $_, $h{$_}], @xx ) {
> > my ( $x, $y) = @$_;
> > print "x: $x, y: $y\n";
> > }
>
> No. That will generally fail when the elements in @xx aren't unique.
Too true. I was telling myself, "but that requires an extra copy of
everything", and I missed the real reason it's wrong.
> > Here's another. :-)
> >
> > {{
> > my $i=0;
> > sub rewind{$i=0}
> > sub eAch(\@\@){$i>$#{$_[0]}&&$i>$#{$_[1]}?():($_[0][$i],$_[1][$i ++])}
> > }}
>
> Oh, the double-brace convention. I'm feeling flattered :)
Just wanted to show I wasn't sleeping in class. :-) An aspect of that
convention that appeals particularly is, I think, that it somewhat
emulates file-scoping traits in your module example. That is, the
lexicals in each package would not be seen in the other packages. Yes, a
single brace would work, too, but being double is an instant clue.
> > while( my( $x, $y ) = eAch( @xx, @yy ) ) {
> > print "x: $x, y: $y\n";
> > }
>
> Another variation of the each-for-lists theme, with a nice use of
> prototypes. If we had a prototype for "arbitrarily many of \@", this
> could be generalized to a step-by-step transposition routine for any
> number of parallel arrays.
Yes. I'm imagining tricks using eval, overload, Hairy? But inspiration
is low.
Regards,
Brad
------------------------------
Date: Fri, 5 Dec 2003 10:21:05 -0500
From: "Scot" <blank@blank.blank.com>
Subject: printf question
Message-Id: <bqq7mt$15i@library1.airnews.net>
Having trouble figuring out how to do this:
Have a number, say 15109.
How do I use printf to make it 15.109? And then 15.1 (I think this can be
done with a %f printf)?
Thanks,
Scott
------------------------------
Date: Fri, 05 Dec 2003 09:26:00 -0600
From: Tony Curtis <tony_curtis32@_SPAMTRAP_yahoo.com>
Subject: Re: printf question
Message-Id: <87vfov2smv.fsf@limey.hpcc.uh.edu>
>> On Fri, 5 Dec 2003 10:21:05 -0500,
>> "Scot" <blank@blank.blank.com> said:
> Having trouble figuring out how to do this: Have a number,
> say 15109.
> How do I use printf to make it 15.109? And then 15.1 (I
> think this can be done with a %f printf)?
Do you mean: as in some European locales where "." is used to
separate digits in large numbers like "," does in English?
Or do you want to perform arithmetic operations (division) on
the value, then output the value to a certain precision?
hth
t
------------------------------
Date: Fri, 5 Dec 2003 11:15:47 -0500
From: "Scot" <blank@blank.blank.com>
Subject: Re: printf question
Message-Id: <bqqate$k3c@library1.airnews.net>
Hi Tony,
it will be representing the decimal in and English number. so i want to
move it over a certain number of spaces to the left, in this example, it
would move two spaces to the left...then have everything but one number to
the right chopped off.
Thanks,
Scott
"Tony Curtis" <tony_curtis32@_SPAMTRAP_yahoo.com> wrote in message
news:87vfov2smv.fsf@limey.hpcc.uh.edu...
> >> On Fri, 5 Dec 2003 10:21:05 -0500,
> >> "Scot" <blank@blank.blank.com> said:
>
> > Having trouble figuring out how to do this: Have a number,
> > say 15109.
>
> > How do I use printf to make it 15.109? And then 15.1 (I
> > think this can be done with a %f printf)?
>
> Do you mean: as in some European locales where "." is used to
> separate digits in large numbers like "," does in English?
>
> Or do you want to perform arithmetic operations (division) on
> the value, then output the value to a certain precision?
>
> hth
> t
------------------------------
Date: Fri, 05 Dec 2003 16:27:07 +0000
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: printf question
Message-Id: <bqqbkr$450$1@south.jnrs.ja.net>
Scot wrote:
> "Tony Curtis" wrote
>>>>"Scot" <blank@blank.blank.com> said:
>>
>>>Having trouble figuring out how to do this: Have a number,
>>>say 15109.
>>
>>>How do I use printf to make it 15.109? And then 15.1 (I
>>>think this can be done with a %f printf)?
>>
>>Do you mean: as in some European locales where "." is used to
>>separate digits in large numbers like "," does in English?
>>
>>Or do you want to perform arithmetic operations (division) on
>>the value, then output the value to a certain precision?
>
> Hi Tony,
>
> it will be representing the decimal in and English number.
> so i want to move it over a certain number of spaces to the
> left, in this example, it would move two spaces to the
> left...then have everything but one number to the right
> chopped off.
perl -e "printf('%.1f',(1509/100))"
15.1
Adjust to taste..
HTH
Simon.
------------------------------
Date: Fri, 5 Dec 2003 11:35:38 -0500
From: "Scot" <blank@blank.blank.com>
Subject: Re: printf question
Message-Id: <bqqc2m$r3k@library1.airnews.net>
Thanks Simon. I just came across an idea from someone that i might use that
is similar where i will use length() to adjust the number of 0's that i use
in the division.
Thanks,
Scott
"Simon Andrews" <simon.andrews@bbsrc.ac.uk> wrote in message
news:bqqbkr$450$1@south.jnrs.ja.net...
> Scot wrote:
> > "Tony Curtis" wrote
>
> >>>>"Scot" <blank@blank.blank.com> said:
> >>
> >>>Having trouble figuring out how to do this: Have a number,
> >>>say 15109.
> >>
> >>>How do I use printf to make it 15.109? And then 15.1 (I
> >>>think this can be done with a %f printf)?
> >>
> >>Do you mean: as in some European locales where "." is used to
> >>separate digits in large numbers like "," does in English?
> >>
> >>Or do you want to perform arithmetic operations (division) on
> >>the value, then output the value to a certain precision?
> >
> > Hi Tony,
> >
> > it will be representing the decimal in and English number.
> > so i want to move it over a certain number of spaces to the
> > left, in this example, it would move two spaces to the
> > left...then have everything but one number to the right
> > chopped off.
>
> perl -e "printf('%.1f',(1509/100))"
> 15.1
>
> Adjust to taste..
>
> HTH
>
> Simon.
>
------------------------------
Date: 5 Dec 2003 07:25:10 -0800
From: oso@uncoma.edu.ar (Eduardo)
Subject: Printing raw characters?
Message-Id: <3d281369.0312050725.3929f017@posting.google.com>
Hi, I need to send a very simple control string to a device. I have
the proper sequence stored in a file:
[root@blah cgi-bin]# od -bc fiscal2.txt
0000000 015 012 230
\r \n 230
0000003
I'm using perl v5.8.0 on a RH9 machine. When I try to print that
sequence, I get the last octal char converted to what I think is
UTF-16:
[root@blah cgi-bin]# perl -e 'print "\r\n\230"' | od -bc
0000000 015 012 302 230
\r \n 302 230
0000004
Do I need to circumvent UTF-16 locale conversion?
How to get it right? Thank you in advance!
------------------------------
Date: Fri, 5 Dec 2003 15:37:39 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Printing raw characters?
Message-Id: <bqq8o3$bqh$1@wisteria.csv.warwick.ac.uk>
oso@uncoma.edu.ar (Eduardo) wrote:
> I'm using perl v5.8.0 on a RH9 machine. When I try to print that
> sequence, I get the last octal char converted to what I think is
> UTF-16:
> [root@blah cgi-bin]# perl -e 'print "\r\n\230"' | od -bc
> 0000000 015 012 302 230
> \r \n 302 230
> 0000004
>
utf8.
[side issue: why are you testing things as root?]
> Do I need to circumvent UTF-16 locale conversion?
> How to get it right?
Perl is outputting utf8 because you have a UTF8 locale set. You have
three options:
1. Change your locale.
2. Upgrade to >=5.8.1, where this behaviour was removed.
3. perl -e'binmode STDOUT; print "\r\n\230"'
This should *really* go in a FAQ...
Ben
--
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks] ben@morrow.me.uk
------------------------------
Date: Fri, 05 Dec 2003 19:45:29 +0200
From: Tassos <chatasos@yahoo.com>
Subject: read file & check input with regex
Message-Id: <1070646438.936989@athprx02>
I'm using the following routine in order to read a file into an array.
Is there a way, while doing that, to store into the array only lines starting with "%"?
if (open(FILE, $ErrorMessagesFile)) {
@ErrorMessages = <FILE>;
close(FILE) ;
} else {
print "Can't open $file : $!\n";
exit 1;
}
------------------------------
Date: Fri, 5 Dec 2003 17:58:28 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: read file & check input with regex
Message-Id: <bqqh04$j1m$2@wisteria.csv.warwick.ac.uk>
Tassos <chatasos@yahoo.com> wrote:
> I'm using the following routine in order to read a file into an
> array. Is there a way, while doing that, to store into the array
> only lines starting with "%"?
>
> if (open(FILE, $ErrorMessagesFile)) {
> @ErrorMessages = <FILE>;
@ErrorMessages = grep /^%/, <FILE>;
Ben
--
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else * ben@morrow.me.uk
------------------------------
Date: 05 Dec 2003 18:04:01 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: read file & check input with regex
Message-Id: <u9zne7p2em.fsf@wcl-l.bham.ac.uk>
Tassos <chatasos@yahoo.com> writes:
> I'm using the following routine in order to read a file into an array.
> Is there a way, while doing that, to store into the array only lines starting with "%"?
>
> if (open(FILE, $ErrorMessagesFile)) {
> @ErrorMessages = <FILE>;
> close(FILE) ;
> } else {
> print "Can't open $file : $!\n";
> exit 1;
> }
Well for small files you could use
@ErrorMessages = grep /^%/, <FILE>;
but that still slurps the file so you probably shouldn't so that.
while ( my $line = <FILE> ) {
push @ErrorMessages, $line if $line =~/^%/;
}
BTW: consider using die() rather than print and exit.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5898
***************************************