[24922] in Perl-Users-Digest
Perl-Users Digest, Issue: 7172 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 24 06:06:45 2004
Date: Fri, 24 Sep 2004 03:05:09 -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 Fri, 24 Sep 2004 Volume: 10 Number: 7172
Today's topics:
Counting most frequently-occurring n-grams in a file (o <_>
Re: Counting most frequently-occurring n-grams in a fil <someone@example.com>
Re: Create a chinese directory (folder) by Perl in Win <nmihai_year_2000@yahoo.com>
DBI::ODBC Remote Login to Server <ackcomm@JUNKcomcast.net>
Re: DBI::ODBC Remote Login to Server <matthew.garrish@sympatico.ca>
Does the executable generated from perlcc needs the lib (Ling)
Re: Does the executable generated from perlcc needs the <kalinaubears@iinet.net.au>
Find location of substring in string? <BLOCKSPAMfishfry@your-mailbox.com>
Re: Find location of substring in string? <see@sig.invalid>
Re: Find location of substring in string? <sholden@flexal.cs.usyd.edu.au>
Re: Find location of substring in string? <notvalid@email.com>
Re: Find location of substring in string? <bart.lateur@pandora.be>
Re: Is it possible to embed perl inside a shell script <tintin@invalid.invalid>
Re: Is it possible to embed perl inside a shell script <david@tvisnospam.co.uk>
Re: order a semicolon-separated data file by a value of <mritty@gmail.com>
Re: Perl script to clean up file -- Dont know if it can <jodyman@hotmail.com>
Re: Permagick Fonts <bart.lateur@pandora.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 24 Sep 2004 17:27:40 +1000
From: "C3" <_>
Subject: Counting most frequently-occurring n-grams in a file (or over multiple files)
Message-Id: <4153cc6b$0$20124$afc38c87@news.optusnet.com.au>
I'm looking for, or willing to write, a program that will take a list of
files as command-line arguments, and then build up a frequency table of
n-grams (individual bytes, or strings of 2 or more bytes) for all these
files.
e.g. ngram 4 file1.txt file2.txt
would return the most frequently occurring sequences of 4 bytes over the two
files.
I am willing to go quick'n'dirty for this. I understand I need to build up a
table of all the n-grams that exist in each file. Can someone help me get
started on this?
cheers,
------------------------------
Date: Fri, 24 Sep 2004 08:02:40 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Counting most frequently-occurring n-grams in a file (or over multiple files)
Message-Id: <AwQ4d.146861$XP3.70635@edtnps84>
C3 wrote:
> I'm looking for, or willing to write, a program that will take a list of
> files as command-line arguments, and then build up a frequency table of
> n-grams (individual bytes, or strings of 2 or more bytes) for all these
> files.
>
> e.g. ngram 4 file1.txt file2.txt
>
> would return the most frequently occurring sequences of 4 bytes over the two
> files.
>
> I am willing to go quick'n'dirty for this. I understand I need to build up a
> table of all the n-grams that exist in each file. Can someone help me get
> started on this?
Well if it's quick'n'dirty that you want:
perl -lne'BEGIN{$r="."x shift}$h{$1}++while/(?=($r))/g}{print for keys%h' 4
file1.txt file2.txt
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 24 Sep 2004 06:20:38 GMT
From: "Mihai N." <nmihai_year_2000@yahoo.com>
Subject: Re: Create a chinese directory (folder) by Perl in Windows 2000 English OS
Message-Id: <Xns956DED96C7240MihaiN@204.127.199.17>
>> I am a perl newbie, and I am trying to use a perl program to create a
>> folder in Window2000. My WINDOWS 2000 is English OS, but setup using
>> Chinese (PRC) as default locale. I am able to create chinese folders
>> manually, and able to view them.
If you have the default system locale set to Chinese, it should work.
From "Control Panel" open "Regional Options", "General" tab, then
"Set Default" (button, left-bottom), select "Chinese (PRC)", "Ok", reboot.
User locale is not enough.
> Use the Encode module to convert the path into UTF16, which is what M$ use
> for international stuff. (completely untested)
Unlikely. Perl.exe is not a Unicode application.
--
Mihai
-------------------------
Replace _year_ with _ to get the real email
------------------------------
Date: Thu, 23 Sep 2004 19:58:42 -0500
From: Fred Goldberg <ackcomm@JUNKcomcast.net>
Subject: DBI::ODBC Remote Login to Server
Message-Id: <Xns956DD566777E8fredackcommcom@216.196.97.142>
Novice - So no flames please.
I have perl script that connects to our Win2000 Server which is running
MS SQL Server. My data base handle statement is:
my $dbh = DBI->connect('DBI:ODBC:DB_Name', 'DB_Login', 'DB_PWD') or
die "Couldn't connect to database: " . DBI->errstr;
The above works fine in the office from my networked PC. I would like to
be able to run this program from home via the Internet. I know my
server's IP address, user_login and user_password.
1) How can I modify my $dbh to accomodate this?
2) Do I need to configure "Data Sources (ODBC)" under my login on the
remote server so it points to "DB_Name"?
Thanks.
Fred
------------------------------
Date: Thu, 23 Sep 2004 21:49:57 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: DBI::ODBC Remote Login to Server
Message-Id: <63L4d.27574$pA.1749387@news20.bellglobal.com>
"Fred Goldberg" <ackcomm@JUNKcomcast.net> wrote in message
news:Xns956DD566777E8fredackcommcom@216.196.97.142...
> Novice - So no flames please.
>
> I have perl script that connects to our Win2000 Server which is running
> MS SQL Server. My data base handle statement is:
>
> my $dbh = DBI->connect('DBI:ODBC:DB_Name', 'DB_Login', 'DB_PWD') or
> die "Couldn't connect to database: " . DBI->errstr;
>
> The above works fine in the office from my networked PC. I would like to
> be able to run this program from home via the Internet. I know my
> server's IP address, user_login and user_password.
> 1) How can I modify my $dbh to accomodate this?
> 2) Do I need to configure "Data Sources (ODBC)" under my login on the
> remote server so it points to "DB_Name"?
>
You need to configure a similarly named ODBC source on your home computer
pointing to the IP of the server with the db. You shouldn't need to change
the connection string at all.
Matt
------------------------------
Date: 23 Sep 2004 16:19:41 -0700
From: niu_ling@yahoo.com (Ling)
Subject: Does the executable generated from perlcc needs the library(.pm) files in the same place as compilation time
Message-Id: <14451bce.0409231519.59bd5eac@posting.google.com>
Hi,
Does the executable generated from perlcc need the .pm files in the
same place as compilation time? I can't get the compiled code run on a
machine with different perl home. I tried setting PREL5LIB, it didn't
help. It keeps on complaining not being able to find the .pm files. It
looks like it hardcode the path for .pm files during compilation. Is
this the expected behavior? If yes, are there other utilities to
compile the perl code into binary and not hardcode the path for .pm?
Thanks a lot,
Ling
------------------------------
Date: Fri, 24 Sep 2004 17:07:55 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Does the executable generated from perlcc needs the library(.pm) files in the same place as compilation time
Message-Id: <4153c8fe$0$24401$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
Ling wrote:
> Hi,
>
> Does the executable generated from perlcc need the .pm files in the
> same place as compilation time? I can't get the compiled code run on a
> machine with different perl home. I tried setting PREL5LIB, it didn't
> help. It keeps on complaining not being able to find the .pm files. It
> looks like it hardcode the path for .pm files during compilation. Is
> this the expected behavior? If yes, are there other utilities to
> compile the perl code into binary and not hardcode the path for .pm?
> Thanks a lot,
>
You'll get better milage with the PAR module's pp utility.
PAR has its own mailing list (see http://lists.perl.org ).
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Fri, 24 Sep 2004 02:19:22 GMT
From: fishfry <BLOCKSPAMfishfry@your-mailbox.com>
Subject: Find location of substring in string?
Message-Id: <BLOCKSPAMfishfry-617E92.19201823092004@netnews.comcast.net>
I can't remember the function that, given "abcdef" and "de" returns 3,
indicating the character position, starting from 0, where "de" is found
in "abcdef".
A secondary question is, how do I use perldoc and the other online docs
when I can't remember the name of the function I'm looking for? For
example I remembered substr(), but that goes the other way, returning
the string occurring at a particular character position.
And my third question is, how can I do this as part of a pattern match?
For example I want to do something like
if ($foo =~ /\d\d/) {
# do stuff
}
where what I really want to know is WHERE within $foo, a pair of digits
occurred.
Thank you all kindly in advance.
------------------------------
Date: Thu, 23 Sep 2004 22:47:55 -0400
From: Bob Walton <see@sig.invalid>
Subject: Re: Find location of substring in string?
Message-Id: <41538904$1_5@127.0.0.1>
fishfry wrote:
> I can't remember the function that, given "abcdef" and "de" returns 3,
> indicating the character position, starting from 0, where "de" is found
> in "abcdef".
Check out the index() function.
>
> A secondary question is, how do I use perldoc and the other online docs
> when I can't remember the name of the function I'm looking for? For
> example I remembered substr(), but that goes the other way, returning
> the string occurring at a particular character position.
Well, one might look at the start of perldoc perlfunc where all the
functions are listed by category. In the case of index(), you'll find
it in the "scalars and strings" category.
>
> And my third question is, how can I do this as part of a pattern match?
> For example I want to do something like
>
> if ($foo =~ /\d\d/) {
> # do stuff
> }
>
> where what I really want to know is WHERE within $foo, a pair of digits
> occurred.
Check out the @- and @+ variables. See:
perldoc perlvar
for documentation.
...
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 24 Sep 2004 02:58:04 GMT
From: Sam Holden <sholden@flexal.cs.usyd.edu.au>
Subject: Re: Find location of substring in string?
Message-Id: <slrncl739s.eak.sholden@flexal.cs.usyd.edu.au>
On Fri, 24 Sep 2004 02:19:22 GMT,
fishfry <BLOCKSPAMfishfry@your-mailbox.com> wrote:
> I can't remember the function that, given "abcdef" and "de" returns 3,
> indicating the character position, starting from 0, where "de" is found
> in "abcdef".
index
>
> A secondary question is, how do I use perldoc and the other online docs
> when I can't remember the name of the function I'm looking for? For
> example I remembered substr(), but that goes the other way, returning
> the string occurring at a particular character position.
By reading the "Perl Functions by Category" section of the perlfunc
documentation and checking the functions in the approproate
category.
Or by searching for words probably used to describe it (since you know
what it does you should be able to make a few guesses). For this
example I'd be searching for "substring", "search", "position", "index",
and so on. Either by grepping the documentation on my machine or
via google.
>
> And my third question is, how can I do this as part of a pattern match?
> For example I want to do something like
>
> if ($foo =~ /\d\d/) {
> # do stuff
> }
>
> where what I really want to know is WHERE within $foo, a pair of digits
> occurred.
See the 'pos' function, though you need to change things to use /g to
use it (which is a significant change).
See the perlre documentation.
You can also do something like /^(.*)\d\d/ and check length($1) (assuming no
\n characters in the string).
--
Sam Holden
------------------------------
Date: Fri, 24 Sep 2004 05:05:55 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: Find location of substring in string?
Message-Id: <TWN4d.782$JG2.511@newssvr14.news.prodigy.com>
Sam Holden wrote:
> Either by grepping the documentation on my machine or via google.
I've always wished that perldoc would support something like that. It's
kind of a -q but for perlfunc text, and would return a list of function
names whose texts match the query regexp.
Maybe one day, when I muster enough courage, I'll submit a patch.
--Ala
------------------------------
Date: Fri, 24 Sep 2004 06:13:05 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Find location of substring in string?
Message-Id: <4ie7l0thv2ad81m3997bfm5o3brsjnmka7@4ax.com>
fishfry wrote:
>And my third question is, how can I do this as part of a pattern match?
>For example I want to do something like
>
> if ($foo =~ /\d\d/) {
> # do stuff
> }
>
>where what I really want to know is WHERE within $foo, a pair of digits
>occurred.
Read perlvar, for the arrays @- and @+ . For example, $-[1] holds the
offset where $1 starts, and $+[1] where it ends. The array index 0 is
used for the whole match, so you should be interested in $-[0] .
--
Bart.
------------------------------
Date: Fri, 24 Sep 2004 19:33:15 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Is it possible to embed perl inside a shell script say bash?
Message-Id: <2ri0scF1a2e9rU1@uni-berlin.de>
"Shawn Corey" <shawn.corey@sympatico.ca> wrote in message
news:6HF4d.28604$bL1.1113545@news20.bellglobal.com...
> zzapper wrote:
> 8< snipped
>> Any ideas?
>
> Yes, skip the shell and use Perl directly. Perl can do anything your shell
> can do, only better. It is also portable. And add in all the neat stuff at
> CPAN http://www.cpan.org/ it's hard to justify using shell.
Actually, it's very easy to justify using the shell as there are plenty of
operations that are easier/better suited to a shell script.
------------------------------
Date: Fri, 24 Sep 2004 09:18:54 GMT
From: zzapper <david@tvisnospam.co.uk>
Subject: Re: Is it possible to embed perl inside a shell script say bash?
Message-Id: <qfp7l0tqnojih1a612npuhscu4v622h379@4ax.com>
On 23 Sep 2004 19:33:28 GMT, wrote:
>At 2004-09-23 03:15PM, zzapper <david@tvisnospam.co.uk> wrote:
>> Hi,
>> Many years ago I used to embed AWK into a shell script, I've tried doing this with Perl with limited
>> results
>>
> #!/bin/bash
> perlscript='
> for $i (1..4) { $j="goat$i"; print " billy$j"; }
> # make the script as arbitrarily long as you like,
> # taking care to avoid single quotes
> my $string = q{a single quoted string};
> ...
> '
> fred=$(perl -e $perlscript)
> echo $fred
>
> # or just write your perl code "inline"
> out=`perl -e '
> # perl code here
> '`
Glenn,
That looks good, I wasn't sure before if a Perl one-liner didn't have certain limits.
But if anyone could suggest a method which frees me of the single quote constraint, does shell have
a hereis method?
zzapper (vim, cygwin, wiki & zsh)
--
vim -c ":%s%s*%Cyrnfr)fcbafbe[Oenz(Zbbyranne%|:%s)[[()])-)Ig|norm Vg?"
http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips
------------------------------
Date: Thu, 23 Sep 2004 18:59:29 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: order a semicolon-separated data file by a value of a column
Message-Id: <civkgv$osj$1@misc-cct.server.rpi.edu>
Stefan H. wrote:
> On Wed, 22 Sep 2004 18:13:47 -0400, Paul Lalli <mritty@gmail.com> wrote:
>
>>My suggestion would be to read each element, store each line in an array
>>reference, store each reference in a larger array, sort the array by the
>>fifth element of each 'inner' array, and then print the results to a new
>>file:
>>
<snipped the code I posted>
>
> Hi Paul, thank you very much for the suggestions.
You're welcome.
>
> I removed declarations and open file checking to have a lighter code to
> post here.
Posting complete, correct code is far more important than saving a few
keystrokes.
> Mi idea was:
>
> - create a list containing each row
> - apply to that list the sort function
> - the sort function need to split each row and compare the fifth element
>
> now I know that I don't know how sort function works :-)
Correct. The sort function returns a list of the elements passed in, in
sorted order. It does not actually touch the list at all. HOWEVER,
even if sort() did directly modify the list you pass it, your code would
still not have worked. You built an array from the file, sorted that
array, and then read from the file again.
> Your code works very well, thanks. I'm learning perl since last week, I
> need it for my work and I'm still a beginner.
Without meaning any disrespect, that was pretty obvious. :) Allow me
then to give you some friendly advice, both about Perl and about this
newsgroup:
1) Do not 'top-post'. That means do not post your reply above what you
are replying to. I have corrected your reply into the proper order in
this post.
2) Comment your code. Explaining in your comments what you are
expecting the code to do will help people correct your faulty beliefs.
3) Read the available documentation. All installations of Perl come
with the 'perldoc' command. For instructions on using it, type 'perldoc
perldoc' at your command prompt. For example, if 'sort' isn't working
the way you think it is, read up on why:
perldoc -f sort
4) Read the Perl FAQ to find if perhaps your question has been asked so
frequently that the answer is documented:
perldoc perlfaq
or
perldoc -q <keyword>
> I didn't know perl had
> references, I read the lama book and it does't mention references. I've
> just ordered the second volume by swartz (perl objects...) I think I
> need it.
Schwartz. Randal L. Schwartz. He posts to this newsgroup from time to
time, so it's best to spell his name correctly.
In the meantime before your copy of the Alpaca arrives, consider reading
the available tutorials and references dealing with references:
perldoc perlreftut
perldoc perllol
perldoc perldsc
perldoc perlref
> Thanks again you and others answered my question.
You're welcome. We wish you the best of luck in your Perl experiences.
Feel free to post questions when you get stuck... but please try to
follow my advice. :)
Paul Lalli
------------------------------
Date: Fri, 24 Sep 2004 03:16:36 GMT
From: "Jodyman" <jodyman@hotmail.com>
Subject: Re: Perl script to clean up file -- Dont know if it can be done
Message-Id: <okM4d.1079$%06.777@newsread3.news.atl.earthlink.net>
> And I get this: WHAT I NEED!
> 5555002,00 0 04 27,TELN NOT BILL
> 1555007,00 0 06 00,CUSTOMER HAS
> 2555010,00 0 12 10,CUSTOMER HAS
>
> I want to try to eliminate as much manual intervention as I can.
This works:
while (<DATA>) {
if ( /(\d{7})\s+(\d\d \d \d\d \d\d)\s+(.*$)/ ) { print "$1,$2,$3\n"; }
}
__DATA__
REPORT NAME: FACICL
0 CLIENT JOB NUMBER: 23405
0 CLIENT NAME: LAURA XXXXXXXX
0 CLIENT MAILING CODE: D509H
0 REPORT DATE: 04/07/08
0 REPORT TIME: 12:46
1REPORT NO: FACRPT14 SOME INFO HERE
RUN DATE: 04JUL10
0 JOB NAME: FACCTICL CUTOVER ACCARE INTERFACE
REJECT REPORT PAGE NO: 2
0 PROGRAM : FACB5500 CUTOVER: LEAF CUTOVER
DATE: 04JUL09
0 TELN CUTTELN CUTOEN REJECT REASON
---- ------- -------------- -------------
-----------------
0 1555200 00 0 12 02 CUSTOMER HAS
2555206 00 0 05 01 CUSTOMER HAS
4555208 00 0 03 06 TELN NOT BILL
1REPORT NO: FACRPT14 SOME DATA HERE
RUN DATE: 04JUL10
0 JOB NAME: FACCTICL CUTOVER ACCARE INTERFACE
REJECT REPORT PAGE NO: 3
0 PROGRAM : FACB5500 CUTOVER: LEAF CUTOVER
DATE: 04JUL09
0 TELN CUTTELN CUTOEN REJECT REASON
---- ------- -------------- -------------
-----------------
0 1555200 00 0 12 02 CUSTOMER HAS
2555206 00 0 05 01 CUSTOMER HAS
4555208 00 0 03 06 TELN NOT BILL
- REJECTED = 000000145 CUTOVER = 000000213
- *** SUCCESSFUL COMPLETION OF
FACCTICL ***
------------------------------
Date: Fri, 24 Sep 2004 06:09:02 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Permagick Fonts
Message-Id: <uqd7l05t9p9bj81dnflkuhrjk3fdqqrl76@4ax.com>
Julia De Silva wrote:
>Has anyone any experience of putting text on top of images using Perlmagick,
>in fact can anyone give us a few clues on using fonts with this module.
Pretty text usage on ImageMagick is based upon Freetype2 (Freetype1 >=
1.1 for older versions of Imagemagick). You'll need that package
installed before you can use it in Imagemagick, and in PerlMagick. See
the install docs that came with ImageMagick to see which one you need.
<http://www.freetype.org/>
--
Bart.
------------------------------
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 7172
***************************************