[19207] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1402 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 29 21:10:44 2001

Date: Sun, 29 Jul 2001 18:10:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <996455412-v10-i1402@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 29 Jul 2001     Volume: 10 Number: 1402

Today's topics:
    Re: Need help on processing some data <goldbb2@earthlink.net>
        Newbie question about date <armour@patarmour.com>
    Re: Newbie question about date <mbudash@sonic.net>
        Perl is a c program <NOSPAM.dogansmoobs@ctel.net>
    Re: Perl is a c program <nowhere@dot.com>
    Re: Regular Expression <tong_po_and_malene@hotmail.com>
    Re: Sorting problem <monty@primenet.com>
        starting an application and then passing a file to it? <cryofan@mylinuxisp.com>
    Re: starting an application and then passing a file to  <cryofan@mylinuxisp.com>
    Re: starting an application and then passing a file to  <somewhere@in.paradise.net>
    Re: Stripping extention from a filename in a string <goldbb2@earthlink.net>
    Re: Stripping extention from a filename in a string <tony_curtis32@yahoo.com>
    Re: Stripping extention from a filename in a string (Mario Rizzuti)
    Re: Stripping extention from a filename in a string <godzilla@stomp.stomp.tokyo>
        Tie with assignment operator variants (was Re: local an <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 29 Jul 2001 18:42:46 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Need help on processing some data
Message-Id: <3B649166.950C4FB9@earthlink.net>

Tim wrote:
> 
> Hi,
> 
> Could someone help me on this ?
> 
> I have a sample input as follow:
> 
> companyXYZ:ABC:1
> companyXYZ:DEF:3
> companyZZZ:ABC:5
> companyZZZ:DEF:7
> 
> I would like to have the output as follow:
> 
>          companyXYZ      companyZZZ
> ABC      1               5
> DEF      3               7
> 
> Any help/hint would be greatly appreciate !

#! perl -w
use strict;
my (%data, %colsizes, $col0);
while( <DATA> ) {
	chomp;
	my ($company, $key, $val) = split /:/;
	$data{$key}{$company} = $val;
	for( $company, $val ) {
		$colsizes{$company} = length
			if( $colsizes{$company} < length );
	}
	$col0 = length $key if( $col0 < length $key );
}

my @companies = sort keys %colsizes;
my $picture = join " ",  # see formline and write for details
	( '<' x $col0 ),   # of how $picture is used.
	map { '>' x $_ } @colssizes{@companies};

$^A = "";
formline( $picture, "", @companies);
formline( $picture, $_, @data{$_}{@companies} ) for( sort keys %data );
print $^A;

__DATA__
companyXYZ:ABC:1
companyXYZ:DEF:3
companyZZZ:ABC:5
companyZZZ:DEF:7
companyQQQ:DEF:9
companyXYZ:GHI:2
__END__

This will handle empty cells, and it will size columns to fit the
company names and the data, and right align everything but column 0
(which is left aligned).

-- 
I need more taglines. This one is getting old.


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

Date: Sun, 29 Jul 2001 20:19:53 GMT
From: "Patrick Armour" <armour@patarmour.com>
Subject: Newbie question about date
Message-Id: <Jd_87.20165$4S4.1717939@typhoon.kc.rr.com>

I'm fairly new to perl so if I don't explain this correctly please forgive
me.

I'm having a difficult time figuring out a way to access the file date.  I'm
trying to write a script that will modify an html page each time a file (in
this case a user database) has been modified.

Any recommendations would be greatly appreciated.
--

Patrick Armour
Network System Administrator
NetWorks Technical Support Team
http://www.cjnetworks.com

785-270-1317
800-469-1411 ext 1317




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

Date: Sun, 29 Jul 2001 20:34:37 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Newbie question about date
Message-Id: <mbudash-4B1DBC.13283129072001@news.sonic.net>

In article <Jd_87.20165$4S4.1717939@typhoon.kc.rr.com>, "Patrick 
Armour" <armour@patarmour.com> wrote:

> I'm fairly new to perl so if I don't explain this correctly please 
> forgive
> me.
> 
> I'm having a difficult time figuring out a way to access the file date.  
> I'm
> trying to write a script that will modify an html page each time a file 
> (in
> this case a user database) has been modified.
> 
> Any recommendations would be greatly appreciated.

http://www.perldoc.com/perl5.6/pod/func/X.html
http://www.perldoc.com/perl5.6/pod/func/stat.html
 
hth-
-- 
Michael Budash ~~~~~~~~~~ mbudash@sonic.net


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

Date: Sun, 29 Jul 2001 14:32:01 -0400
From: Mik Mifflin <NOSPAM.dogansmoobs@ctel.net>
Subject: Perl is a c program
Message-Id: <tm8ljsikglj74e@corp.supernews.com>

I'm trying to embed perl scripts into a C program, and I'm having a bit of 
trouble.  It seems that I am missing a library or something?  I get the 
following error when I try to compile:

/usr/lib/perl5/5.6.0/i586-linux/CORE/libperl.a(pp.o): In function 
Perl_pp_crypt:
pp.o(.text+0x6483): undefined refrence to crypt.

It seems to me like I'm missing a library.  Or maybe part of glibc?  I seem 
to remember there being a package for glibc called glibc-crypt, but I 
thought that was integrated into the latest release of glibc?  Anyway, any 
help here would be cool.  Thanks in advance.

-- 
 - Mik Mifflin
dogansmoobs at ctel dot net


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

Date: Mon, 30 Jul 2001 08:49:55 +1000
From: "Gregory Toomey" <nowhere@dot.com>
Subject: Re: Perl is a c program
Message-Id: <3b097.17167$a04.67997@newsfeeds.bigpond.com>

"Mik Mifflin" <NOSPAM.dogansmoobs@ctel.net> wrote in message
news:tm8ljsikglj74e@corp.supernews.com...
> I'm trying to embed perl scripts into a C program, and I'm having a bit of
> trouble.  It seems that I am missing a library or something?  I get the
> following error when I try to compile:
>
> /usr/lib/perl5/5.6.0/i586-linux/CORE/libperl.a(pp.o): In function
> Perl_pp_crypt:
> pp.o(.text+0x6483): undefined refrence to crypt.
>
> It seems to me like I'm missing a library.  Or maybe part of glibc?  I
seem
> to remember there being a package for glibc called glibc-crypt, but I
> thought that was integrated into the latest release of glibc?  Anyway, any
> help here would be cool.  Thanks in advance.
>
> --
>  - Mik Mifflin
> dogansmoobs at ctel dot net

You may want to look at perlembed
http://www.perldoc.com/perl5.6/pod/perlembed.html

gtoomey




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

Date: Sun, 29 Jul 2001 23:24:55 +0100
From: "John Taylor" <tong_po_and_malene@hotmail.com>
Subject: Re: Regular Expression
Message-Id: <9k22aq$nm3$1@newsg1.svr.pol.co.uk>

Oh yes. Doh!

Thanks guys,

Lee.


"Lee" <tong_po_and_malene@hotmail.com> wrote in message
news:9jvt93$hgv$1@news8.svr.pol.co.uk...
> if ($string !~ /\D/)
>
> Only checks the first character!
>
> Why the reverse logic? Shouldn't that be if ($string =~ /\d/) ?
>
> Thanks anyway,
>
> Lee.
>
> "Ilmari Karonen" <iltzu@sci.invalid> wrote in message
> news:996267379.20496@itz.pp.sci.fi...
> > In article <996237059.10050.0.nnrp-14.c2de1f0e@news.demon.co.uk>, Lee
> Osborne wrote:
> > >"Lee Osborne" <osbornelee@hotmail.com> wrote in message
> > >news:996079173.11940.0.nnrp-01.c2de1f0e@news.demon.co.uk...
> > >>
> > >> What is the regular expresssion to check whether a string contains
ONLY
> > >> numbers?
> > >
> > >$idLengthIn = length($input);
> > >if ($input{'document_id'} =~ /\d{$idLengthIn}/) {
> > >   print "Digits ONLY!";
> > >}
> > >else {
> > >   print "Not just digits!";
> > >}
> >
> > That works.  This should be simpler and quicker, however:
> >
> >   if ($input{document_id} !~ /\D/) {
> >       print "Digits only.  Could be empty..\n";
> >   } else {
> >       print "Contains a non-digit.\n";
> >   }
> >
> > --
> > Ilmari Karonen -- http://www.sci.fi/~iltzu/
> > "Get real!  This is a discussion group, not a helpdesk.  You post
> something,
> > we discuss its implications.  If the discussion happens to answer a
> question
> > you've asked, that's incidental."           -- nobull in
> comp.lang.perl.misc
> >
>
>




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

Date: 29 Jul 2001 23:57:44 GMT
From: Jim Monty <monty@primenet.com>
Subject: Re: Sorting problem
Message-Id: <9k27to$na8$2@nnrp1.phx.gblx.net>

Jonathan Sala <jonathan.sala@wichita.boeing.com> wrote:
> Is there a sort module that will sort the following first by
> alphanumerically and then the last part numerically.  
>
> Example:  Sort the following
> 	  abc23 abc113 cde34 abc5 cde4 def77 abc1
>
> Into the following:
> 	  abc1 abc5 abc23 abc113 cde4 cde34 def77
>
> Is there some sort module I should use to do this or just create my own
> own routine to do this?

As Ilmari Karonen pointed out, there does exist a module for this
purpose. Depending on your circumstances, however, you may find it
simpler just to roll your own sort, especially since there are now
several well-known idioms for doing this efficiently:

  #!/usr/bin/perl -lw
  # sort alphanumeric strings of form aaa999 using Schwartzian Transform
  print join q{ },
        map   { $_->[0] }
        sort  { $a->[1] cmp $b->[1] || $a->[2] <=> $b->[2] }
        map   { m/^(\D*)(\d*)/; [ $_, $1, $2 ] }
        qw    { abc23 abc113 cde34 abc5 cde4 def77 abc1 };
  __END__

-- 
Jim Monty
monty@primenet.com
Tempe, Arizona USA


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

Date: Sun, 29 Jul 2001 14:46:38 -0500
From: Tiberius Gracchus <cryofan@mylinuxisp.com>
Subject: starting an application and then passing a file to it?
Message-Id: <e0q8mtkppjdpc7so735pi2en8ua0vmdlpu@4ax.com>

starting an application and then passing a file to it?

I want to start an exe file and then pass a binary data file to it.

Any guesses on how to do this?


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

Date: Sun, 29 Jul 2001 15:43:41 -0500
From: Tiberius Gracchus <cryofan@mylinuxisp.com>
Subject: Re: starting an application and then passing a file to it?
Message-Id: <6bt8mtolc9bp4e14d3jloqqpcipqtnli41@4ax.com>

On Sun, 29 Jul 2001 14:46:38 -0500, Tiberius Gracchus
<cryofan@mylinuxisp.com> wrote:

>starting an application and then passing a file to it?
>
>I want to start an exe file and then pass a binary data file to it.
>
>Any guesses on how to do this?
 I am trying to do this in windows 98...



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

Date: Mon, 30 Jul 2001 10:34:32 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: starting an application and then passing a file to it?
Message-Id: <y_197.10$OU1.182343@news.interact.net.au>


"Tiberius Gracchus" <cryofan@mylinuxisp.com> wrote in message
news:e0q8mtkppjdpc7so735pi2en8ua0vmdlpu@4ax.com...
> starting an application and then passing a file to it?
>
> I want to start an exe file and then pass a binary data file to it.
>
> Any guesses on how to do this?

prog.exe file.dat

I suspect this is not really what you wanted, but your question is so vague
as to be meaningless.





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

Date: Sun, 29 Jul 2001 14:32:53 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Stripping extention from a filename in a string
Message-Id: <3B6456D5.6269F566@earthlink.net>

Jason LaPenta wrote:
> 
> Hi,
> 
> I have a string var $filename = "filename.ext" and I want it to be
> turned into $filename = "filename" by removing the ".ext" How can I do
> this? I've been reading about pattern matching for an hour and can't
> find even the slightest reference the such and operation.

$filename =~ s/^(.+)\..*$/$1/;

This will change "filename.ext" to "filename", while leaving names like
".emacs" or ".newsrc" intact.

Of course, since you usually want to get both the basename and the
extention, something like the following may be preferred:

($base, $ext) = $filename =~ m/^(.+?)(\.[^.]*)?$/;

This should turn "filename.ext" into ("filename",".ext"), and turn
".emacs" into (".emacs", "").

-- 
I need more taglines. This one is getting old.


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

Date: 29 Jul 2001 13:26:47 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Stripping extention from a filename in a string
Message-Id: <87u1zviobc.fsf@limey.hpcc.uh.edu>

>> On Thu, 26 Jul 2001 20:32:07 -0400,
>> Jason LaPenta <lapenta_jm@yahoo.com> said:

> Hi, I have a string var $filename = "filename.ext" and I
> want it to be turned into $filename = "filename" by
> removing the ".ext" How can I do this? I've been reading
> about pattern matching for an hour and can't find even
> the slightest reference the such and operation.

This is what File::Basename was written for.

  http://search.cpan.org/doc/ILYAZ/perl_mlb/File/Basename.pm

hth
t
-- 
Beep beep!  Out of my way, I'm a motorist!


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

Date: 29 Jul 2001 14:11:22 -0700
From: mariorizzuti@yahoo.com (Mario Rizzuti)
Subject: Re: Stripping extention from a filename in a string
Message-Id: <42f3ee2.0107291311.7d3dee05@posting.google.com>

Godzilla! <godzilla@stomp.stomp.tokyo> wrote in message 3B64481B.14EB5CDB@stomp.stomp.tokyo...
> Mario Rizzuti AKA The CLPM Troll wrote:

> > Other than the extension length, which is actually nothing so
> > important (just change the number?) I see 2 behaviours that maybe
> > could be considered as wrong.
> 
>  
> > - if the string has not dots, it will not be returned "as is" (rindex
> > returns -1 on failure, so the last char will be cutted).
> 


> Spin your beanie propeller and cite an example of a valid
> file extension which is not preceeded by a period.


"godzilla" is a legal filename, although it should be prohibited.

> 
> > - if there are 2 or more dots, just the one more at right will be
> > cutted (rindex will match the first occurence starting from the
> >   end).


> Spin your beanie propeller again and cite an example of a
> valid file extension preceeded by two periods.

godzilla..txt
god.zilla.txt

Looking better at it, it seems ok to considers just the dot on the right.

---
Mario Rizzuti


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

Date: Sun, 29 Jul 2001 14:47:14 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Stripping extention from a filename in a string
Message-Id: <3B648462.79546BE4@stomp.stomp.tokyo>

Mario Rizzuti AKA The CLPM Troll wrote:
 
> Godzilla! wrote:
> > Mario Rizzuti AKA The CLPM Troll wrote:

(snipped)


> > Spin your beanie propeller and cite an example of a valid
> > file extension which is not preceeded by a period.
 
> "godzilla" is a legal filename, although it should be prohibited.

Where is the extension? 

print "Duh! " x 10**1000000;
 

> > Spin your beanie propeller again and cite an example of a
> > valid file extension preceeded by two periods.
 
> godzilla..txt

print "Sure! Happens All The Time! " x 10**1000000;


> god.zilla.txt

I do not read two preceeding periods.

print "Duh! " x 10**1000000;

 
> Looking better at it, it seems ok to considers just the dot on the right.

print "Lame Brain Troll! " x 10**1000000;


Godzilla!


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

Date: Sun, 29 Jul 2001 18:17:00 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Tie with assignment operator variants (was Re: local and tie)
Message-Id: <3B648B5C.F40DA5D1@earthlink.net>

Ilmari Karonen wrote:
> 
[snip]
> What *I* would really like is if tied scalars could somehow atomically
> handle the assignment variants of operators.  That would let me fix a
> minor but irritating bug in Time::Stopwatch.

What syntax would you propose?

I would suggest about a pragma, "tie", which takes arguments similar to
the "overload" pragma, but where the subs for "overload" get the blessed
object as the first value, then the other args for the operator, this
would get a tied object and a key, then the rest of the args.

Eg, if the object is a tied hash or array:
use tie "+=" => sub { my ($self, $key, $rhs, $inv) = @_; .... };


-- 
I need more taglines. This one is getting old.


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

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


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