Chris Cole
Sep 30 2004, 09:59 AM
On Thu, 30 Sep 2004 11:18:08 +0100, Gavin Henry wrote:
QUOTE |
Roime bin Puniran said: How can i rename any file using PERL?...Where should i start?..Where i can find any tutorial?
using linux:
man mv
you can use a system() call or backticks ``
|
Why would you want to do that when you've got a specific perl command?
Gavin Henry
Sep 30 2004, 03:57 PM
QUOTE |
Moreover, rename() is a basic part of Perl, so even on Linux there is no need to do this with a system call to the `mv` command.
|
Of course, doh.
--
Just getting into the best language ever...
Fancy a [Email Removed]? Just ask!!!
NYIMI Jose \
Oct 1 2004, 08:22 AM
QUOTE |
-----Original Message----- From: Gabor Urban [mailto:[Email Removed]] Sent: Friday, October 01, 2004 11:05 AM To: [Email Removed] Subject: Re: Becoming Disenheartened - Everyone talks about Python and saysPerl is old news.
Hi guys,
this thread seems to expand into something unworthy of this mailing list. You can not compare a cup of tea with a horse, these are two totally different things.
Both Perl and Python have it's place under the sun, both have very good features, and some very difficult aspects, too. Both can be perfect for the right tasks, but may be terrible choices for others. THe real point if you write your code correct, know what you are doing and make possible for others to understand your source. The difference is between good and poor developer. IMHO I could write this about any other language, for example Cobol, too :-))))
I am doing Python programming for living now, but create reports on my log useng Perl. Perfect, smooth and efficient.
|
Agreed as well !
Could you guys keep this thread constructive or STOP it ... Please ?
Thx,
Jos.
**** DISCLAIMER ****
"This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above.
Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited.
If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer".
Thank you for your cooperation.
For further information about Proximus mobile phone services please see our website at
http://www.proximus.be or refer to any Proximus agent.
Nicolay A. Vasiliev
Oct 1 2004, 09:10 AM
Absolutely :)
Gavin Henry wrote:
QUOTE |
Could you guys keep this thread constructive or STOP it ... Please ?
It's been very constructive for me :-)
I have just read this famous peice:
http://www.linuxjournal.com/article.php?si...=&order=&thold=
I am going to learn both and make up my own mind. I think that's the best for any hacker.
Gavin.
Best regards, |
Randal L. Schwartz
Oct 1 2004, 10:07 AM
QUOTE |
"Gavin" == Gavin Henry <[Email Removed]> writes:
|
Gavin> I have just read this famous peice:
Gavin>
http://www.linuxjournal.com/article.php?si...=&order=&thold=I'm pretty sure that Eric Raymond is not fully aware of
test-first-development and Test::More and proper module packaging of
Perl. Otherwise, he wouldn't keep spouting his "Perl sucks for big
projects" mantra.
Perl's object model is complete. Perl scales well to large projects.
That Eric Raymond was unable to get it to scale is more telling about
Eric than about Perl.
I say this even though I consider Eric at least a strong acquaintence,
having met him on quite a few occasions. Eric is doing a disservice
to the Perl community though, and on that, I cannot let stand.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +
<[Email Removed]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Doug Lewis
Oct 1 2004, 10:44 AM
I won't even reply to the person that said, perl is old news. And that everyone talks about Python. That is just stupid. Most people either talk about C, C++, or Java. Then comes perl.
Perl is still way more talked about than Python In my Experience.
Perl makes things much simpler.
"NYIMI Jose (BMB)" <[Email Removed]> wrote:
QUOTE |
-----Original Message----- From: Nicolay A. Vasiliev [mailto:[Email Removed]] Sent: Friday, October 01, 2004 2:45 PM To: [Email Removed] Subject: Re: Becoming Disenheartened - Everyone talks about Python and says Perl is old news.
To Randal and Chris. You all don't understand me. CGI is a module, earlier wrote and stored in a separate files. I don't mean such objects.
Python and Ruby don't write the code for me. But look at this Python code:
s = "I am Perl guru"; new_s = s.replace("Perl", "Python");
|
With this willing to treat everything as object you end up with
Ugly code such as the following:
http://www.python.org/cgi-bin/moinmoin/CgiScripts#!/usr/bin/env python
import cgi
print "Content-type: text/html"
print
print
print """
Sample CGI Script
"""
form = cgi.FieldStorage()
if form.has_key( "message" ):
message = form["message"].value
else:
message = "(no message)"
print """
Previous message: %s
form:
message: [input]
""" % message
That I let the beginners-list to show you how it can be nicer written in Perl :)
Jos.
**** DISCLAIMER ****
"This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above.
Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited.
If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer".
Thank you for your cooperation.
For further information about Proximus mobile phone services please see our website at
http://www.proximus.be or refer to any Proximus agent.
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
---------------------------------
Do you Yahoo!?
vote.yahoo.com - Register online to vote today!
Bob Showalter
Oct 1 2004, 02:47 PM
Jan Eden wrote:
QUOTE |
Hi,
I try to call wget using system like this:
system("wget -O /dev/null", "http://janeden.org/test/file.txt");
This does not work:
Can't exec "wget -O /dev/null": No such file or directory at ./wgetrec.pl line 6.
Ok, so how about this:
system("wget", "-O /dev/null http://janeden.org/test/file.txt");
No go:
wget: missing URL
Without additional options,
system("wget", "http://janeden.org/test/file.txt");
works fine.
How can I pass an option to system's first argument in a setting like this?
|
This is explained in 'perldoc -f system'
You either need to separate all the args yourself, or pass a single string
to system so the shell can split the args. You're trying to do both.
either:
system("wget -O /dev/null
http://janeden.org/test/file.txt")or:
system('wget', '-O', '/dev/null', 'http://janeden.org/test/file.txt')
NYIMI Jose \
Oct 1 2004, 02:39 PM
QUOTE |
-----Original Message----- From: Nicolay A. Vasiliev [mailto:[Email Removed]] Sent: Friday, October 01, 2004 2:45 PM To: [Email Removed] Subject: Re: Becoming Disenheartened - Everyone talks about Python and says Perl is old news.
To Randal and Chris. You all don't understand me. CGI is a module, earlier wrote and stored in a separate files. I don't mean such objects.
Python and Ruby don't write the code for me. But look at this Python code:
s = "I am Perl guru"; new_s = s.replace("Perl", "Python");
|
With this willing to treat everything as object you end up with
Ugly code such as the following:
http://www.python.org/cgi-bin/moinmoin/CgiScripts#!/usr/bin/env python
import cgi
print "Content-type: text/html"
print
print
print """
<html>
<head><title>Sample CGI Script</title></head>
<body>
<h3> Sample CGI Script </h3>
"""
form = cgi.FieldStorage()
if form.has_key( "message" ):
message = form["message"].value
else:
message = "(no message)"
print """
<p>Previous message: %s</p>
<p>form:</p>
<form method="post" action="index.cgi">
<p>message: <input type="text" name="message"/></p>
</form>
</body>
</html>
""" % message
That I let the beginners-list to show you how it can be nicer written in Perl :)
Jos.
**** DISCLAIMER ****
"This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above.
Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited.
If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer".
Thank you for your cooperation.
For further information about Proximus mobile phone services please see our website at
http://www.proximus.be or refer to any Proximus agent.
Wiggins d Anconia
Oct 1 2004, 02:53 PM
QUOTE |
On Fri, 2004-10-01 at 11:04 +0200, Gabor Urban wrote: Hi guys,
this thread seems to expand into something unworthy of this mailing list. You can not compare a cup of tea with a horse, these are two totally different things. Don't be ridiculous, of course they don't compare, a horse is _way_ more useful than a cup of tea, horses plow fields, they provide transportation, and when attached to a Hansom Cab, they can even get men laid! A cup of tea has none of these features. So please, no more disparaging horses by comparing them to cups of tea, this sort of madness _must_ stop!
--uv
|
"Teach a man to fish, and he will sit in a boat and drink beer all day."
Careful some of the Briton's are probably pretty sensitive over their
tea ;-)....
I think this thread has definitely deteriorated.
http://danconia.org
William M West
Oct 1 2004, 03:41 PM
(code snipped to save space)
i found the Python script to be very readable- i am far more comfortable
with Perl syntax, but it worked for me.
I think there are two arguments which can be made here- both good.
1. code syntax (limitation/flexibility/readability) - how languages
differ and language preference.
2. Language strengths and weaknesses (outside of syntax).
My impression was that OO in Perl has historically been fraught with
CPU overhead - this will change in Perl 6? (argument number 2)
I like the functional() as apposed to the menthod.syntax() because i can
more easily visualise the path that data takes through the code. makes
my life easier (argument number 1)
for me something like $new_s = change($s, $string); just works better
for me. anyway, the advantages of encapsulation are easily produced in
functional() code with good coding practices.
of course, now we're talking about meta topics as apposed to particular
Perl
questions- but I think the argument is worth while.
willy
http://www.hackswell.com/corenth
Randal L. Schwartz
Oct 2 2004, 12:11 AM
QUOTE |
"William" == William M West <[Email Removed]> writes:
|
William> My impression was that OO in Perl has historically been fraught with
William> CPU overhead - this will change in Perl 6? (argument number 2)
FUD FUD FUD.
*All* late binding takes a bit of time. Perl caches what it can.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +
<[Email Removed]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
William M West
Oct 4 2004, 11:11 AM
QUOTE |
William> My impression was that OO in Perl has historically been fraught with William> CPU overhead - this will change in Perl 6? (argument number 2)
FUD FUD FUD.
*All* late binding takes a bit of time. Perl caches what it can.
|
well, i'll be a mother's son! I figured that Perl had to have /some/
problems somewhere.
interesting.
willy
http://www.hackswell.com/corenth
I am trying to call this command from a webpage
killall -USR2 appname
I have had no luck with PHP exec() or system() someone said I needed to
learn Perl as it handles this stuff better. Can someone point me to a sample
of this kind of system call in perl so I can learn??
Any help would be appreciated
Eric
Charles K. Clarkson
Oct 5 2004, 04:33 AM
atul ashpalia <[Email Removed]> wrote:
Please reply to the list.
: Thanks in advance for your help. please find the
: attached "filltasks.cgi".
Why attached it? Show it inline. where it is easier
to view.
You are not using strict and warnings. How did you
learn perl?
use strict;
use warnings;
: use CGI;
:
: $query = new CGI;
my $query = new CGI;
: print $query->header;
:
: print<<"EOF";
:
: <HTML>
: <HEAD>
: <TITLE>Daily Report</TITLE>
: </HEAD>
: <BODY BGCOLOR="#EEFFFF">
[snipped form]
: <br>
: <a href="filltasks.cgi">New Task</a>
:
: <br><br><br>
: <input type="submit" value="Submit">
:
: </center>
: </form>
:
: </BODY>
: </HTML>
:
: EOF
First thing you need to do is name your input fields
and text areas. The name you use for the first fieldset
would probably be numbered and the next ones would increment.
: There's a hyperlink 'New Tasks' above the submit button. On
: click of which i want to add the whole 'Fill Tasks' section
: below the first one.
You would need some indicator to tell the script that a
new field is being added.
<a href="filltasks.cgi?action=new_task">New Task</a>
Then in the script you would need to check the 'action'
parameter.
if ( $query->param( 'action' ) eq 'new_task' ) {
# add fieldset with new names for each input
# and print larger form
} else {
# print small form
}
Your next problem is how to maintain data across page
updates and how to increment field names for each new
fieldset. You might use a link like this.
<a href="filltasks.cgi?action=task-1">New Task</a>
And then in the new link use
<a href="filltasks.cgi?action=task-2">New Task</a>
To preserve data you could use a submit button instead of
a link. These should submit the form allowing data to be kept
across pages.
<input type="hidden" name="task-count" value="1">
<input type="submit" name="new-task" value="Add a new task">
: Then, the same hyperlink should appear below the
: second 'Fill Tasks' section so that i can include the
: third 'Fill Tasks' section below the second one, on
: click of that link. And So on...
: That is, the user may want to include as many tasks he/she want
: to enter.
:
: On submit button click, the page is directed to
: 'displaytasks.cgi' wherein i will display the user's data.
You'd probably do better sending it to the same script
as produced it.
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
NYIMI Jose \
Oct 5 2004, 01:38 PM
QUOTE |
-----Original Message----- From: Randal L. Schwartz [mailto:[Email Removed]] Sent: Tuesday, October 05, 2004 4:31 PM To: [Email Removed] Subject: Re: Email syntax validation
Silly person.
|
Oh oh! What's this ?
I can't imagine that's comes from Randal :-(
Jos.
**** DISCLAIMER ****
"This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above.
Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited.
If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer".
Thank you for your cooperation.
For further information about Proximus mobile phone services please see our website at
http://www.proximus.be or refer to any Proximus agent.
Randal L. Schwartz
Oct 5 2004, 01:41 PM
QUOTE |
"NYIMI" == NYIMI Jose (BMB) <[Email Removed]> writes:
Silly person.
|
NYIMI> Oh oh! What's this ?
NYIMI> I can't imagine that's comes from Randal :-(
Why not? It's saying what I feel about that. I'm using "silly"
rather casually here. Maybe that's not coming through very well in
email. Imagine me saying it while I'm chuckling light-heartedly.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +
<[Email Removed]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
JupiterHost.Net
Oct 5 2004, 02:28 PM
Randal L. Schwartz wrote:
QUOTE |
"NYIMI" == NYIMI Jose (BMB) <[Email Removed]> writes:
Silly person.
NYIMI> Oh oh! What's this ? NYIMI> I can't imagine that's comes from Randal :-(
Why not? It's saying what I feel about that. I'm using "silly" rather casually here. Maybe that's not coming through very well in email. Imagine me saying it while I'm chuckling light-heartedly.
|
or maybe followed by "Trix are for kids" ? :)
Bob Showalter
Oct 5 2004, 07:48 PM
James Taylor wrote:
QUOTE |
I posted this to the mod_perl list 2 days ago, but it seems a bit inappropriate there as the discussion is much more advanced than my question... That and I haven't gotten a response, so sorry for the crosspost :)
I'm running apache 1.3.x with the associated version of mod_perl, but am having trouble creating regular old include files to be used with helper functions. Works just great with regular old CGI, mod_perl doesn't like it. Say for example I have two files, main.pl and helper.pl.
# helper.pl sub dowhatever() { # this is completely pointless, i'm just using it as an example my %params=@_; my $p; foreach my $k(sort keys %params) { $k =~ s/'$//g; $p.=$k; } return $p; } 1;
# main.pl #!/usr/bin/perl use strict; use Apache::Constants qw(OK DECLINED SERVER_ERROR FORBIDDEN); use Apache::Cookie (); require('helper.pl');
#..............some stuff my $q=&dowhatever(%somehash);
That doesn't work in the least, I keep getting errors in my apache logs saying sub dowhatever is an undefined function, etc. Is it possible to even do anything like this in mod_perl, or do I need to write an Apache module / Perl Module just to have helper functions in there?
|
FWIW, That example works OK for me under Apache 1.3.31, mod_perl 1.29 when I
run under Apache::Registry. I had to add a declaration for %somehash, but
otherwise it runs without error. Is main.pl running under Apache::Registry,
or is it a PerlHandler or some other type of handler?
It always makes me nervous to see assumptions about the current working
directory in any web server stuff. You should code the full path to
helper.pl, or better, create a proper module and pull it in with use.
James Taylor
Oct 5 2004, 08:25 PM
Bob Showalter wrote:
QUOTE |
FWIW, That example works OK for me under Apache 1.3.31, mod_perl 1.29 when I run under Apache::Registry. I had to add a declaration for %somehash, but otherwise it runs without error. Is main.pl running under Apache::Registry, or is it a PerlHandler or some other type of handler?
It always makes me nervous to see assumptions about the current working directory in any web server stuff. You should code the full path to helper.pl, or better, create a proper module and pull it in with use.
Here's a better example of something that actually might serve a bit |
more purpose along with the error I'm getting for THIS
particular example.
And yes, this is running under Apache::Registry:
test.pl:
#!/usr/bin/perl
use strict;
use Apache::Constants qw(OK DECLINED SERVER_ERROR FORBIDDEN);
use Apache::Cookie ();
require('lib/helper.pl');
print "Content-type: text/htmlnn";
my $rand=&genrand(20);
print "<html><body>$rand</body></html>";
helper.pl:
sub genrand {
my $l=@_; my $r;
my @chars=('a'..'z','A'..'Z','0'..'9','_');
$r.=$chars[rand @chars] for(1..$l);
return $r;
}
1;
When running test.pl, I get the following in my logs:
Use of uninitialized value in foreach loop entry at lib/helper.pl line 4.
Use of uninitialized value in foreach loop entry at lib/helper.pl line 4.
Use of uninitialized value in concatenation (.) or string at
/export/home/newsite/perl/test.pl line 10.
So, what I can gather is that the value '20' isn't being received by the
genrand subroutine, and it's getting something else instead. What
exactly, I'm not sure
but I know it has to do SOMETHING with Apache::Registry. To test things
out, I went ahead and changed the genrand sub to spit out what it was
receiving:
sub genrand {
my @blah=@_; my $r;
$r.="$_<br />n" for @blah;
return $r;
}
What did it return? "20<br />"
Now how the hell that happened, I don't know, but it STILL isn't getting
that value passed. Any idea what apache's sending here and why it
doesn't want to
grab the variable?
Paul Johnson
Oct 6 2004, 09:01 AM
On Tue, Oct 05, 2004 at 02:25:08PM -0700, James Taylor wrote:
QUOTE |
Here's a better example of something that actually might serve a bit more purpose along with the error I'm getting for THIS particular example.
sub genrand { my $l=@_; my $r;
|
I'm not sure that this will solve everything, but you likely want
my ($l) = @_;
QUOTE |
my @chars=('a'..'z','A'..'Z','0'..'9','_'); $r.=$chars[rand @chars] for(1..$l); return $r; }
So, what I can gather is that the value '20' isn't being received by the genrand subroutine, and it's getting something else instead. What exactly, I'm not sure
|
I would have expected $l to be set to 1, the number of elements in @_.
--
Paul Johnson - [Email Removed]
http://www.pjcj.net
Gunnar Hjalmarsson
Oct 6 2004, 01:07 PM
Anish Kumar K. wrote:
QUOTE |
I am in process of creating a template Say a HTML template...pasting one sample line below.
<td width="1" bgcolor="#[%topColor%]"><img border="0" src="[%1x1_image%]" width="1" height="100%"></td
and there is one text file(config.txt) has several entries
1x1_image=/images/temp_white.gif topColor=FFFFFF
|
You can store config.txt in a hash and use the s/// operator:
my %tmpl_vars = (
'1x1_image' => '/images/temp_white.gif',
topColor => 'FFFFFF',
);
for (@data) {
s{[%([^%]s]+)%]}
{ $tmpl_vars{$1} or die "Unknown tmpl var: [%$1%]n" }eg;
}
The /g modifier allows for multiple substitutions at each line.
As long as it is as simple as you have described here, this approach
is sufficient IMO. For a more advanced template system, I'd go for one
of the template modules.
--
Gunnar Hjalmarsson
Email:
http://www.gunnar.cc/cgi-bin/contact.pl
Randy W. Sims
Oct 6 2004, 09:36 PM
On 10/6/2004 6:21 PM, Eduardo Vzquez Rodrguez wrote:
QUOTE |
I have the following questions
1. Doing that, how do I use the new perl binary 5.8.5 instead of the old 5.8.0? I believe that /usr/local/bin/perl is pointing to the older version instead of the newer
|
It's just a link to the versioned executable. Change the link to point
to /usr/local/bin/perl5.8.5.
Bob Showalter
Oct 7 2004, 11:24 AM
Bee wrote:
QUOTE |
Hello,
I am curious to know that if that is an existed module to open files with it's default application just like I double click on the file with mouse. and I do something just like this with my code :
use defaultOpen; defOpen 'C:temp.gif' or die "$!" ; # Then the image will open with photoshop. defOpen 'C:temp.doc' or die "$!" ; # then the document will open with Word.
I've made this done by writting a batch like code.. but I sure that's unsafe and unportable.
|
won't
system "start temp.doc"
do the trick?
Paul Johnson
Oct 7 2004, 09:33 AM
On Thu, Oct 07, 2004 at 11:28:44AM +0200, Michael Seele wrote:
QUOTE |
i'm new to perl and i want to know if perl has reflection like java? how can i acces reflection and how powerfull is the reflection in perl?
|
You might want to narrow this down a bit to get real information, but:
http://java.sun.com/docs/books/tutorial/reflect/ says
] The reflection API represents, or reflects, the classes, interfaces,
] and objects in the current Java Virtual Machine. You'll want to use
] the reflection API if you are writing development tools such as
] debuggers, class browsers, and GUI builders. With the reflection API
] you can:
] * Determine the class of an object.
ref()
] * Get information about a class's modifiers, fields, methods,
] constructors, and superclasses.
] * Find out what constants and method declarations belong to an
] interface.
You would probably use can(), @ISA and, depending of the base type of
the class, exists().
] * Create an instance of a class whose name is not known until
] runtime.
bless $obj, $class
] * Get and set the value of an object's field, even if the field name
] is unknown to your program until runtime.
$obj->{$field} = $value
] * Invoke a method on an object, even if the method is not known
] until runtime.
$obj->$method
] * Create a new array, whose size and component type are not known
] until runtime, and then modify the array's components.
my @arr;
$arr[$index] = $value
You can also access the symbol table at runtime, and use the B modules
to access a lot of internal information. But I don't think you'll need
to at first.
You'll need to learn to think the Perl way to get the best from the
language. You could program Perl as if it were Java, and do everything
you want to, but if you're using Perl, you might as well work to its
strengths.
--
Paul Johnson - [Email Removed]
http://www.pjcj.net
Bob Showalter
Oct 7 2004, 03:18 PM
COUNTERMAN, DANIEL (CONTRACTOR) wrote:
QUOTE |
All,
I have a Perl script I am running from an HTML page that will save the output in a file called comments.txt. Is there anyway I can email this file everytime to an email address that I provide.
|
Be forewarned: this kind of thing tends to turn into a huge gaping security
risk, opening your server to being used as an open relay for spammers.
Google on "formmail exploit", for example.
The safest approach would be to avoid sending mail from your CGI program
altogether. If the data goes into comments.txt, have a separate process (not
runnable from the web server) that forwards that file to you.
Thanks thanks, a very nice lesson again !! Feel quite sorry that I even
never heard about this command for using windows after so many
years...
Thousands thanks,
Bee
----- Original Message -----
From: "Bob Showalter" <[Email Removed]>
To: "'Bee'" <[Email Removed]>; <[Email Removed]>
Sent: Thursday, October 07, 2004 8:24 PM
Subject: RE: Open file with default application software on Windows ?
QUOTE |
Bee wrote: Hello,
I am curious to know that if that is an existed module to open files with it's default application just like I double click on the file with mouse. and I do something just like this with my code :
use defaultOpen; defOpen 'C:temp.gif' or die "$!" ; # Then the image will open with photoshop. defOpen 'C:temp.doc' or die "$!" ; # then the document will open with Word.
I've made this done by writting a batch like code.. but I sure that's unsafe and unportable.
won't
system "start temp.doc"
do the trick?
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response
|
QUOTE |
I have a Perl script I am running from an HTML page that will save the output in a file called comments.txt. Is there anyway I can email this file everytime to an email address that I provide. This will be running on a Windows platform. Also, if you have better suggestions for what I am trying to accomplish that would be appreciated. I am trying to create a contact form, which will show the input, and email the contents to an email address, and show a successful transmission, and a thank you message, then return to the Home page. Any help would be appreciated, here is what I have.
|
Are you simply trying to email this file everytime this script is executed?
If so, there are a number of modules you can use in this script to do that:
MIME::Lite (great for sending attachments_
Mail::Sender
Mail::Sendmail
Net::SMTP
Simpley google for these and you should find plenty of examples.
I have some example scripts as well I can send you if you like
HTH,
Jim
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.772 / Virus Database: 519 - Release Date: 10/1/2004
Bob Showalter
Oct 7 2004, 08:01 PM
Kent, Mr. John (Contractor) wrote:
....
QUOTE |
my(@ACTIVE) = qw {gid240 gid278 gid301}; my(@LOGGED) = qw {gid306 gid240 gid278 gid301};
# This doesn't work, finds a match for every item in # LOGGED, seems to be matching on "gid" but ignoring the number foreach (@LOGGED){ unless (grep /$_/,@ACTIVE){ print "No Match for $__n" if ($DEBUG == 1); #do something here with what didn't match"; } else { print "found $_ in ACTIVESn" if ($DEBUG == 1); } }
|
Others have explained the localization of $_ issue. It's not important for
such a small data set, but if @ACTIVE is large, you can improve performance
by doing a hash lookup instead of a grep():
use strict;
my(@ACTIVE) = qw {gid240 gid278 gid301};
my(@LOGGED) = qw {gid306 gid240 gid278 gid301};
my %h; @h{@ACTIVE} = ();
print exists $h{$_} ? "Found" : "No match for", " $_n" for @LOGGED;
# MAIN
use test::Foo;
my $x = new test::Foo ( 'SunSet', 'myID', 'myPassword' );
my $y = Clone($x);
my $z = $y -> Clone;
$y->{TEMPLATE} = 'SunRaise';
my $t = 'TEMPLATE';
print $$x{$t} . " " . $$y{$t} . " " . $$z{$t};
# test::Foo
package test::Foo;
use strict;
require Exporter; our @ISA = qw/Exporter/;
our @EXPORT = qw/new Clone/;
sub Clone
{ my $self ; my $class = shift;
$self -> {$_} = $class -> {$_} for (keys %$class);
return bless $self;
}
sub new
{ my $self; shift;
$self -> {TEMPLATE} = shift;
$self -> {ID} = shift;
$self -> {Pass} = shift;
bless $self;
return $self;
}
1;
Follow up on my previous post, I've get my thing cloned, but.. Is it right
way to make a clone like this ? Any more standard way to get the same
job done ?
Thanks in advise,
Bee
PS. I have no idea why I do this or what's the purpose, it just a test
for learning purpose. It's just my very first step into OOPerl...
Randal L. Schwartz
Oct 9 2004, 11:49 AM
QUOTE |
"Bee" == Bee <[Email Removed]> writes:
|
Bee> use test::Foo;
Please name your packages with an initial cap. Lowercase
are reserved for pragmas.
Bee> return bless $self;
You're still needlessly avoiding the two-arg bless, which means your
constructors cannot be inherited.
Bee> PS. I have no idea why I do this or what's the purpose, it just a test
Bee> for learning purpose. It's just my very first step into OOPerl...
Have you read "perldoc perlboot"? If you want more than that,
get "Learning Perl Objects References and Modules".
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +
<[Email Removed]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Todd W
Oct 9 2004, 06:47 PM
"Michael Seele" <[Email Removed]> wrote in message
news:[Email Removed]...
QUOTE |
hi, i'm new to perl and i want to know if perl has reflection like java? how can i acces reflection and how powerfull is the reflection in perl? thx mseele
Perls reflection support is probably my most favorite thing about perl. |
Basically, reflection is built in to perl. No reflection API is needed. You
just use scalar variables that contain class and method names in place of
the actual names and everything works dynamically:
use warnings;
use strict;
package Base;
sub new {
my $class = shift();
my $self = bless( { }, $class );
return( $self );
}
our $line = 1;
sub print {
my $class = shift();
print( $line, ': ', @_, "n" );
$line++;
}
sub foo {
my $proto = shift();
$proto->print('Hello from ', (ref($proto) or $proto), '->foo');
}
sub bar {
my $proto = shift();
$proto->print('Hello from ', (ref($proto) or $proto), '->bar');
}
package ClassA;
use base qw/Base/;
sub foo {
my $proto = shift();
#do work specific for this class, then...
$proto->SUPER::foo();
}
sub bar {
my $proto = shift();
#do work specific for this class, then...
$proto->SUPER::bar();
}
package ClassB;
use base qw/Base/;
sub foo {
my $proto = shift();
#do work specific for this class, then...
$proto->SUPER::foo();
}
sub bar {
my $proto = shift();
#do work specific for this class, then...
$proto->SUPER::bar();
}
package main;
foreach my $class ( qw/ClassA ClassB/ ) {
my $obj = $class->new();
foreach my $method ( qw/foo bar baz/ ) {
if ( $obj->can( $method ) ) {
$obj->$method();
} else {
$class->print("$obj cant $method");
}
}
}
output:
1: Hello from ClassA->foo
2: Hello from ClassA->bar
3: ClassA=HASH(0x15d5218) cant baz
4: Hello from ClassB->foo
5: Hello from ClassB->bar
6: ClassB=HASH(0x1a8941c) cant baz
Todd W.
Luke Bakken
Oct 10 2004, 02:15 PM
QUOTE |
Perl works better than grep because the grep statement you give below does not find any instances of the pattern and perl finds quite a few. I'm using Cygwin on Win2003Server. Since there is something obviously wrong with my cygwin implementation of grep, how do I get the file names with perl?
|
Well, I think this post will be off-topic, but here's what I found using
my Cygwin grep:
I created a DOS text file with these contents:
this
is a test
file
END
END
thouou
END
Some of those ENDs have space characters after them. I ran my cygwin
grep on the file:
C:tmp>c:cygbingrep -n "^ *END *$" testfile
No output.
I changed the text file to have UNIX line endings, then re-ran the
statement:
C:tmp>c:cygbingrep -n " *END *$" testfile
4: END
6:END
10:END
Checking the cygwin mount table, I have the following:
$ mount
C:cygbin on /usr/bin type system (binmode)
C:cyglib on /usr/lib type system (binmode)
C:cyg on / type system (binmode)
c: on /c type system (binmode)
d: on /mnt/d type system (binmode,noumount)
e: on /mnt/e type system (binmode,noumount)
So for kicks I switched the text file back to DOS line endings, and
added the following text mount point:
mount -ts c:\ /c_text
C:tmp>c:cygbingrep -n " *END *$" testfile
C:tmp>c:cygbingrep -n " *END *$" /c_text/tmp/testfile
4: END
6:END
10:END
Voila. That's most likely your problem - a mismatch between line endings
and Cygwin mount point type.
Harry Putnam
Oct 10 2004, 11:27 PM
"Bakken, Luke" <[Email Removed]> writes:
QUOTE |
Voila. That's most likely your problem - a mismatch between line endings and Cygwin mount point type.
|
And in case you hadn't seen them before... there are at least a few
sets of unix tools for dos/windows. Cygwin maybe the best known but
I've used Uwin myself for sometime and never had a problem with its
grep.
http://www.research.att.com/sw/tools/uwin/
Luke Bakken
Oct 11 2004, 12:12 AM
QUOTE |
Voila. That's most likely your problem - a mismatch between line endings and Cygwin mount point type.
And in case you hadn't seen them before... there are at least a few sets of unix tools for dos/windows. Cygwin maybe the best known but I've used Uwin myself for sometime and never had a problem with its grep.
http://www.research.att.com/sw/tools/uwin/
|
Marcos Rebelo
Oct 11 2004, 04:30 AM
Hi all
This is my first question.
One part of my job is to read one e-mail from Pop3 and do a forward of that
e-mail with SMTP to +- 1000 users, just changing the from and the to.
There is something that can eseally do this?
How to do this?
Probably there is some modules that can do this work ease, but where to start?
thanks
Marcos
O SAPO j est livre de vrus com a Panda Software, fique voc tambm!
Clique em:
http://antivirus.sapo.pt
Jenda Krynicky
Oct 11 2004, 02:39 PM
From: [Email Removed]
QUOTE |
One part of my job is to read one e-mail from Pop3 and do a forward of that e-mail with SMTP to +- 1000 users, just changing the from and the to.
There is something that can eseally do this? How to do this?
Probably there is some modules that can do this work ease, but where to start?
|
To receive:
Mail::POP3Client or Net::POP3
To send:
Net::SMTP, Mail::Sender, MIME::Lite, ...
Since you just need to forward the email, Net::SMTP should be enough.
You'll just need to replace the From and To headers (and maybe do
something more with the message headers) and then transfer the data.
Jenda
===== [Email Removed] ===
http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
Wiggins d Anconia
Oct 11 2004, 03:17 PM
QUOTE |
From: [Email Removed] One part of my job is to read one e-mail from Pop3 and do a forward of that e-mail with SMTP to +- 1000 users, just changing the from and the to.
There is something that can eseally do this? How to do this?
Probably there is some modules that can do this work ease, but where to start?
To receive: Mail::POP3Client or Net::POP3
To send: Net::SMTP, Mail::Sender, MIME::Lite, ...
Since you just need to forward the email, Net::SMTP should be enough. You'll just need to replace the From and To headers (and maybe do something more with the message headers) and then transfer the data.
Jenda
|
Though it may be overkill, Mail::Box can achieve all steps of the
process with one module suite. Not to discredit the fine list above,
just another option...
http://danconia.org
Bob Showalter
Oct 12 2004, 12:04 PM
Thomas Drought wrote:
QUOTE |
Hello all,
I was wondering if someone could help me. I have a script which send an HTTP::Request
I would like to be able to view what it is sending. I thought I could just create use HTTP::Daemon for this, but I'm not getting any response from it. I want to see the information from the initial request with headers.
Here is what I have...
Request:
$req = HTTP::Request->new(POST = 'http://localhost:83/cgi-bin/server.cgi' );
|
OK, that creates a request, but it doesn't send it. You need to create an
LWP::UserAgent. Also, your server doesn't bind to port 83, so the request
won't get there.
QUOTE |
And Daemon:
#!/usr/bin/perl
use vars qw( $req $d $c ); ( $req, $d, $c ) = ();
|
"my" is preferred over "use vars" here.
QUOTE |
use strict; use HTTP::Daemon;
$d = HTTP::Daemon->new;
|
Need to bind to port 83 or change your request.
QUOTE |
while ( $c = $d->accept ) { $req = $c->get_request; printf $req
|
print() not printf(). Also you need $req->as_string to get meaningful
results.
QUOTE |
} $c = undef; # don't forget to close the socket
|
Your script will never get to this line.
Here's a self-contained example. The server exits after one request.
#!/usr/bin/perl
use strict;
use LWP::Simple;
use HTTP::Daemon;
my $PORT = 8888;
my $URL = "http://localhost:$PORT/cgi-bin/server.cgi";
defined(my $pid = fork) or die $!;
unless ($pid) {
my $d = HTTP::Daemon->new(LocalPort => $PORT, ReuseAddr => 1)
or die "Couldn't start Daemon";
print "Daemon ready at ", $d->url, "n";
my $c = $d->accept;
my $r = $c->get_request;
print "Request received:n", $r->as_string, "n";
exit;
}
sleep 2; # allow daemon to start
get $URL;
Outputs:
Daemon ready at
http://yourhost.yourdomain.com:8888/Request received:
GET /cgi-bin/server.cgi HTTP/1.0
Host: localhost:8888
User-Agent: lwp-trivial/1.40
Dave Gray
Oct 12 2004, 02:19 PM
QUOTE |
Mi goal is that each thread could process an element of an array that has 10 elements, so thread0 process array[0], thread1 process array[1] and so on until thread9 process array[9]
Those 10 lines come from a file that Perl reads in chunks of ten lines until EOF
|
First of all, your code doesn't /do/ anything with the data you pass
it in proceso...
I'm curious, why 10 lines at a time? And honestly, you probably don't
need threads for this...
my $group_size = 10;
my @accumulator = ();
while (<FILE>) {
chomp;
push @accumulator, $_;
next if $. % $group_size;
# do stuff with @accumulator
}
# do stuff with @accumulator (leftovers)
Some recommended reading on perl threads:
<http://www.perlmonks.org/index.pl?node_id=288022>
<http://www.perldoc.com/cgi-bin/htsearch?words=threads>
And here's some relatively generic threading code that should get you
started (if you still think you need to use threads):
--CODE--
#!/usr/bin/perl -w
use strict;
use threads;
use threads::shared;
our $group_size = 10;
our $num_threads = 3;
our @threads = ();
our @buffer : shared = ();
our $main_done : shared = 0;
sub process_buffer {
my $self = threads->self;
while(1) {
my @rows = ();
{ lock(@buffer);
if (not @buffer) {
if ($main_done) {
cond_broadcast(@buffer);
print STDERR 'thread '. $self->tid ." exitingn";
return;
}
print STDERR 'thread '. $self->tid ." waiting on buffern";
cond_wait(@buffer);
}
next if not $main_done and @buffer < $group_size;
push(@rows, shift(@buffer))
while @buffer and @rows < $group_size;
}
next if not @rows;
print 'thread '. $self->tid .': '. join(', ', @rows) ."n";
} # end infinite while
}
for my $i (1 .. $num_threads) {
print STDERR "starting thread $in";
unshift @threads, threads->create('process_buffer');
}
while (<DATA>) {
chomp;
next unless /^w+/;
lock(@buffer);
# print STDERR "loading buffer up with [$_] on line $.n";
push @buffer, $_;
cond_signal(@buffer) unless $. % $group_size;
}
{ lock($main_done);
print STDERR "main thread donen";
$main_done = 1;
lock(@buffer);
cond_broadcast(@buffer);
}
for my $t (@threads) {
$t->join();
print STDERR 'joined thread '. $t->tid ."n";
}
__DATA__
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Wiggins d Anconia
Oct 13 2004, 01:16 PM
QUOTE |
greetings;
any suggestion for perl's equivalent for jpgraph (www.aditus.nu/jpgraph/) ?
|
A quick search of CPAN turns up some options. I have personally had
success with GD::Graph. Don't know that it is as powerful (read: makes
things as pretty) as the one you mention. Though since they both use GD
presumably everything accomplishable with jpgraph can be done by Perl
and possibly GD::Graph.
Starting here my make some sense:
http://search.cpan.org/modlist/Graphicshttp://danconia.org
Chris Devers
Oct 14 2004, 06:43 AM
On Thu, 14 Oct 2004, Peter Scott wrote:
QUOTE |
In article <[Email Removed]>, [Email Removed] (Wiggins d Anconia) writes:
A quick search of CPAN turns up some options. I have personally had success with GD::Graph. Don't know that it is as powerful (read: makes things as pretty) as the one you mention.
A package that quite possibly is as pretty (I have only done a cursory comparison) is GD::Graph, at http://search.cpan.org/~rdp/GD-Chart-0.05/. It rocks.
|
Wait, so you're saying GD::Graph is as pretty as GD::Graph?
I don't believe you!
:-)
--
Chris Devers
Peter Scott
Oct 14 2004, 08:58 AM
In article <[Email Removed]>,
[Email Removed] (Wiggins d Anconia) writes:
QUOTE |
any suggestion for perl's equivalent for jpgraph (www.aditus.nu/jpgraph/) ?
A quick search of CPAN turns up some options. I have personally had success with GD::Graph. Don't know that it is as powerful (read: makes things as pretty) as the one you mention.
|
A package that quite possibly is as pretty (I have only done a
cursory comparison) is GD::Graph, at
http://search.cpan.org/~rdp/GD-Chart-0.05/. It rocks.
--
Peter Scott
http://www.perldebugged.com/*** NEW ***
http://www.perlmedic.com/
Peter Scott
Oct 14 2004, 03:03 PM
In article <Pine.OSX.4.61..718@macgarnicle>,
[Email Removed] (Chris Devers) writes:
QUOTE |
On Thu, 14 Oct 2004, Peter Scott wrote: In article <[Email Removed]>, [Email Removed] (Wiggins d Anconia) writes:
A quick search of CPAN turns up some options. I have personally had success with GD::Graph. Don't know that it is as powerful (read: makes things as pretty) as the one you mention.
A package that quite possibly is as pretty (I have only done a cursory comparison) is GD::Graph, at http://search.cpan.org/~rdp/GD-Chart-0.05/. It rocks.
Wait, so you're saying GD::Graph is as pretty as GD::Graph?
I don't believe you!
:-)
|
Sigh, too early in the morning.
I got the URL right. The name of the package is GD::Chart.
--
Peter Scott
http://www.perldebugged.com/*** NEW ***
http://www.perlmedic.com/
Chris Devers
Oct 14 2004, 04:31 PM
On Thu, 14 Oct 2004, Dave Kettmann wrote:
QUOTE |
The reply was deserved :) Just another question before I go too far with this... The files I am parsing (just needing 2 tabbed fields out of them) are approximately 20,000 - 25,000 lines long a piece. Each of these files will be globbed into one file, but that is something completely different. I guess my question is, would I be better off calling exec(cut) with files of this size for ease of use? Guess I should have mentioned this in my previous email.
|
Not necessarily.
I seem to remember that as long as you're iterating over a small window
of the file at any given time, you don't necessarily end up slurping the
whole thing into memory at once.
How long is each line? How large are the files, bytewise? And how much
memory (etc) do you have to work with?
This is going to be a situations where benchmarks are invaluable.
--
Chris Devers
Chris Devers
Oct 14 2004, 04:40 PM
On Thu, 14 Oct 2004, Dave Kettmann wrote:
QUOTE |
Each line is probably 80-100 characters in legnth, the files are about 300Kb each (6 files total) working with 1GB of memory.
|
Oh, that's it? I'm sure you'll be find then
QUOTE |
Looking at these numbers, dont know that these are really that big of a file, but seem like it when you look at them in vi ;)...
|
Well, among other things, Vim handles big files more smoothly :-)
--
Chris Devers
Dave Kettmann
Oct 14 2004, 08:19 PM
QUOTE |
-----Original Message----- From: Chris Devers [mailto:[Email Removed]] Sent: Thursday, October 14, 2004 4:16 PM To: Perl List (E-mail) Cc: Dave Kettmann Subject: Re: Perl equivalent to the unix 'cut' command
On Thu, 14 Oct 2004, Chris Devers wrote:
On Thu, 14 Oct 2004, Dave Kettmann wrote:
Subject speaks for itself..
Okay then.
perldoc -f split
Also speaks for itself :-)
To be less snarky, you probably need to open up your file, iterate over it line by line, using split to break each line up into chunks, then write out a new array with the fields you want and the order you want them. This second array can then be written out to disc; if you want you could even read & write within the same loop.
But the key point is that split is often the easiest way to break apart the fields in a file that is, for example, CSV formatted.
Give that a try, write some code to attempt it, and let the list know if you have any problems in getting it to work.
-- Chris Devers
|
Chris,
The reply was deserved :) Just another question before I go too far with this... The files I am parsing (just needing 2 tabbed fields out of them) are approximately 20,000 - 25,000 lines long a piece. Each of these files will be globbed into one file, but that is something completely different. I guess my question is, would I be better off calling exec(cut) with files of this size for ease of use? Guess I should have mentioned this in my previous email.
Thanks again,
Dave
Dave Kettmann
Oct 14 2004, 08:35 PM
QUOTE |
On Thu, 14 Oct 2004, Dave Kettmann wrote:
The reply was deserved :) Just another question before I go too far with this... The files I am parsing (just needing 2 tabbed fields out of them) are approximately 20,000 - 25,000 lines long a piece. Each of these files will be globbed into one file, but that is something completely different. I guess my question is, would I be better off calling exec(cut) with files of this size for ease of use? Guess I should have mentioned this in my previous email.
Not necessarily.
I seem to remember that as long as you're iterating over a small window of the file at any given time, you don't necessarily end up slurping the whole thing into memory at once.
How long is each line? How large are the files, bytewise? And how much memory (etc) do you have to work with?
This is going to be a situations where benchmarks are invaluable.
-- Chris Devers
|
Each line is probably 80-100 characters in legnth, the files are about 300Kb each (6 files total) working with 1GB of memory. Looking at these numbers, dont know that these are really that big of a file, but seem like it when you look at them in vi ;)... I guess I will give slice a shot and see what I can do with it, I will keep you and the list updated :)
Dave Kettmann
Jeff 'japhy' Pinyan
Oct 15 2004, 08:17 AM
On Oct 15, Etienne Ledoux said:
QUOTE |
Would anybody have any idea why chomp is deleting the value ?
No matter how I try and do it. I even tried s/n//,$value . afterwards I have a empty value. I don't understand what I'm doing wrong here and everywhere i check this it seems to be the right way to do it. mmmm ?!?!
|
The problem is that your data ends in rn, and the r is a carriage
return. If you print "jeffrABC", you'd *see* "ABCf", because the r
causes the cursor to go to the beginning of the line, thus overwriting
previous letters. In your case, apparently the IP address is longer than
both the username and the password, so the IP is all you're seeing.
($user = <$client>) =~ s/r?n$//;
($pass = <$client>) =~ s/r?n$//;
That should work for you.
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
Chris Cole
Oct 15 2004, 08:55 AM
On Thu, 14 Oct 2004 17:40:28 -0400, Chris Devers wrote:
QUOTE |
On Thu, 14 Oct 2004, Dave Kettmann wrote:
Each line is probably 80-100 characters in legnth, the files are about 300Kb each (6 files total) working with 1GB of memory.
Oh, that's it? I'm sure you'll be find then
|
Most definitely. I sometimes iterate over 1Gb files in a system with 512Mb
RAM with no problems. It usually takes ~20 seconds to complete so speed
isn't too much of an issue either.
QUOTE |
Looking at these numbers, dont know that these are really that big of a file, but seem like it when you look at them in vi ;)...
Well, among other things, Vim handles big files more smoothly :-) |
Jeff 'japhy' Pinyan
Oct 19 2004, 11:04 AM
On Oct 19, Steve Bertrand said:
QUOTE |
$line =~ s/images//../../images/g;
Leaning toothpicks! You don't need to escape the '.' on the replacement string side because they are literal '.' characters there. Changing the delimiter to something other than '/' will eliminate the need to escape the '/' characters as well.
Yes, as I saw in your post. As you say though, if one does not need to escape the '.'s on the replacement side, because they are literal, should the '' not be literal as well?
|
The right-hand side is a double-quoted string. "." isn't special in a
double-quoted string, but "" is.
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart