Re: Validating form data
On 15 Apr 2002 22:46:33 -0400, [EMAIL PROTECTED] (Daniel Falkenberg) wrote: I am just about to go ahead and start validating form data. I was thinking about tackling it in the following way... $data1 = param(data1); $data2 = param(data2); $data3 = param(data3); $data4 = param(data4); if ($data1 ne Whatever) { print Not equal; elsif ($data2 ne Test) { print Hello world; Of coarse I will be making it a little for stringent :) but is there a better way of tackling this? Hi, if you are going to test your form input, you may as well do it the suggested perl way and use the taint checking process. Read perldoc perlsec. Put -T on your shebang line, and you are in taint-checking mode. To taint check, you setup a regex to extract the $1 from it. Anything passing thru the $1 variable is considered clean. This way, you will be checking your variable, and doing the taintchecking at the same time. The generic variable testing takes this form, where you put in a more suitable regex for your variable. if ($data1 !~ /^(Whatever)$/) { $data1 = $1; # $data now untainted } else {die Bad data in $data1;# log this somewhere } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
conecting cgi and mdb? help please:)
I have install ActivePerl 5.6.1.630 in folder c:\perl then I have run ppm and do the fallowing: PPM install dbi Install package 'dbi?' (y/N): y Installing package 'dbi'... Error installing package 'dbi': Could not locate a PPD file for package dbi PPM this is error message and my question is: 1.way I can't install dbi when I am offline? This package I can install only when I am online like others pelage (INSTALL DBD-Mysql) 2.Can I connect cgi with Microsoft access database *.mdb and how to configure those relationship? 3. Can I use Microsoft access database *.mdb on servers where is supported mysql? 4.How can I reply on messages because I don't see button reply?? Thanks, Dragan
Perl CGI with ISP - advice?
Hi, I'm writing a Perl-based system to allow simple site content management through web forms. I'm a relative beginner to both Perl and CGI, although I have much experience with C, Visual Basic, and relational database programming. The system I'm writing is targeted to non-profits and small businesses, the kinds of outfits which typically will have sites hosted by an ISP, not on their own hardware with their own people to administer it. So my software will need to be (1) small, and (2) installable to a virtual domain cgi-bin path by FTP with normal owner permissions, not system admin and/or shell access. I've found that this cuts down on available technology quite dramatically. One hesitation I have is that most Perl modules assume that you can run an install procedure to install the module in your system. If an outfit has only FTP access to its virtual domain, not shell access or sysadm privilege, the only thing you can do is copy the module's files over from some other place you've installed them (such as my PC's hard drive). This seems to be working with two of the modules I've used so far (HTML::Template and AnyData::CSV), but I'm hesitant to rely too much on a lot of them. Obviously, you run a risk if a module has platform-specific functionality. I'm particularly shy of CGI.pm, both due to size and also uncertainty of if it can be installed by a simple file copy. I'd appreciate any advice anyone could give on the difficulties I might encounter in this endeavor, in particular module size and ability to install on an ISP-hosted virtual domain by FTP alone. Should I be convincing the ISP to install the modules in their /site/lib instead, rather than us putting them in our virtual domain? Is CGI.pm recommended in this situation? Any other issues you would foresee me having? (I already know I'll have to think through security at some point.) Thanks in advance for any replies. - John Brooking - Do You Yahoo!? Yahoo! Tax Center - online filing with TurboTax
Definition
As I am somewhat new to perl can someone tell me what this means $header = qq~ I understand the header but what is the qq~ for? Thanks
Definition
As I am somewhat new to perl can someone tell me what this means $header = qq~ I understand the header but what is the qq~ for? Thanks
Re: Definition
Bill Lyles wrote: href=file://C:\Program Files\Common Files\Microsoft Shared\Stationery\ As I am somewhat new to perl can someone tell me what this means $header = qq~ I understand the header but what is the qq~ for? perldoc -f qq btw, it's considered bad form to send html-ized email to the list. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Cookied
Why isnt my cookie getting saved. - #!/usr/bin/perl -w # WeBeWebin # Browse Admin # Andrew Rosolino # V. 1.0 # Load Modules use DBI; use CGI qw/:standard/; use CGI::Carp 'fatalsToBrowser'; # -- recommended my $q = new CGI; # Making connection to the database; sub DBI { $dsn = DBI:mysql:homewebewebin:localhost; $dbh = DBI-connect($dsn, webewebin,w3b3w3bin) or die $DBI::errstr; $sth = $dbh-prepare(SELECT username,password FROM browse_admin) or die $DBI::errstr; $sth-execute or die $DBI::errstr; ($username,$password) = $sth-fetchrow_array; } unless ($q-param('Act')) { begin; } else { check; } #Start Admin sub begin { if(defined $ENV{HTTP_COOKIE}) { ($a, $b) = split(/=/, $ENV{HTTP_COOKIE}); print $ENV{HTTP_COOKIE}; } print header, start_html('Login Admin'), h1('Login:'), start_form, $ENV{'HTTP_COOKIE'},p, Username: ,textfield('username'),p, Password: ,password_field('password'),p, hidden('Act','check'),p, submit('Login'), end_form; } #Check Admin sub check { DBI; $sth = $dbh-prepare(SELECT username,password FROM browse_admin) or die $DBI::errstr; $sth-execute or die $DBI::errstr; while(($username,$password) = $sth-fetchrow_array) { if($username eq $q-param('username') $password eq $q-param('password')) { bed; } else { print header, Username Or Password Is Incorrect; } } $sth-finish; $dbh-disconnect; } sub bed { $cookie = $q-cookie(-name=$username, -value=$password, -expires='1d', -path='/', -domain='.webewebin.com', -secure=1); print $q-header(-cookie=$cookie),p, Cookie Planted ( I Think.Hope ); print $ENV{'HTTP_COOKIE'}; } -- Andrew __ Do You Yahoo!? Yahoo! Tax Center - online filing with TurboTax http://taxes.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Definition
Ok, Sorry about that Anyway what do you mean perldoc -f qq? what does the ~qq mean? - Original Message - From: fliptop [EMAIL PROTECTED] To: Bill Lyles [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, April 16, 2002 8:53 PM Subject: Re: Definition Bill Lyles wrote: href=file://C:\Program Files\Common Files\Microsoft Shared\Stationery\ As I am somewhat new to perl can someone tell me what this means $header = qq~ I understand the header but what is the qq~ for? perldoc -f qq btw, it's considered bad form to send html-ized email to the list. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl CGI with ISP - advice?
I cannot answer these questions, as I am facing exactly the same situation and have exactly the same set of question myself -- so I will be monitoring closely for any answers! However, as per CGI.pm, I do know that on Tripod/Lycos accts, they install CGI.pl and a number of Tripod*.pl modules for you (optionally). If they do any registration or just copy the files, I don't know, but the text of these install pages indicates that they are just copied to /cgi-bin, nothing more. My new (DomainAvenue*) host also supports PHP4, which I am just now looking at. Quite frankly, for what I want to do (and am currently doing using SSI) this looks like a better initial choice -- I may need additional Perl scripts, but with the MySQL support, more C-like syntax, scripts embedded in HTML Perl-like regexp support, this LOOKS more accessible to me (with a C++, Java, 4-GL programming background, Win-centric lite on Unix shell scripts a lot of SSI-enabled HTML pages to enhance incrementally.) Also, if you're using (client-side) Win (or Linux or Mac, I guess), download ActiveState's Perl Komodo (v1.1 is free for edu / learning / home purposes). Komodo is a Win IDE w/ Perl / PHP / more develop / debugging support. I just dl'd and, initially, it looks GREAT!! http://www.activestate.com *DomainAvenue.com offers: $35/yr w/ domain name/10Mg/SSI/Perl/PHP4/5-POP3/MySQL unlim bandwidth/email aliases/more -- great deal!!! Get one! Tell Carol in support I sent you. http://www.domainavenue.com. *BTW: I am not affiliated in any way with DomainAvenue.com or it's parent Wyith, Inc. -- I am just a very happy customer who wants to spread the word, since they've gone the extra mile (or 100) to support me with ?stupidly simple? questions similar to these. For example, at my request (to lessen MY workload) they enabled SSI for all .html files on all accounts (in addition to .shtml), simply because MY current pages expect it. They've also made numerous changes to the account management pages at my specific request and are working on more right now. And they did it FAST. They are great! David Van Camp Software Development Consulting Patterns, Reuse, Software Process Improvement http://www.davidvancamp.com Visit the OO Pattern Digest! A catalog of condensed patterns, books and related resources http://patterndigest.tripod.com Moving soon to: http://patterndigest.com - Original Message - From: John Brooking [EMAIL PROTECTED] To: Beginners CGI [EMAIL PROTECTED] Sent: Tuesday, April 16, 2002 4:17 PM Subject: Perl CGI with ISP - advice? Hi, I'm writing a Perl-based system to allow simple site content management through web forms. I'm a relative beginner to both Perl and CGI, although I have much experience with C, Visual Basic, and relational database programming. The system I'm writing is targeted to non-profits and small businesses, the kinds of outfits which typically will have sites hosted by an ISP, not on their own hardware with their own people to administer it. So my software will need to be (1) small, and (2) installable to a virtual domain cgi-bin path by FTP with normal owner permissions, not system admin and/or shell access. I've found that this cuts down on available technology quite dramatically. One hesitation I have is that most Perl modules assume that you can run an install procedure to install the module in your system. If an outfit has only FTP access to its virtual domain, not shell access or sysadm privilege, the only thing you can do is copy the module's files over from some other place you've installed them (such as my PC's hard drive). This seems to be working with two of the modules I've used so far (HTML::Template and AnyData::CSV), but I'm hesitant to rely too much on a lot of them. Obviously, you run a risk if a module has platform-specific functionality. I'm particularly shy of CGI.pm, both due to size and also uncertainty of if it can be installed by a simple file copy. I'd appreciate any advice anyone could give on the difficulties I might encounter in this endeavor, in particular module size and ability to install on an ISP-hosted virtual domain by FTP alone. Should I be convincing the ISP to install the modules in their /site/lib instead, rather than us putting them in our virtual domain? Is CGI.pm recommended in this situation? Any other issues you would foresee me having? (I already know I'll have to think through security at some point.) Thanks in advance for any replies. - John Brooking - Do You Yahoo!? Yahoo! Tax Center - online filing with TurboTax -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
uploadfile cgi
Hi could someone tell me what's wrong with this cgi please Every time I try to run the next script througha form I get a 500 Internal Server Error and my http log(apache) gives me this error: [Wed Apr 17 04:08:27 2002] [error] [client 217.129.197.231] script not found or unable to stat: /home/formprof/public_html/cgi-bin/manage.pl here's the script: #!/usr/bin/perl -w use strict; use CGI; use Fcntl qw( :DEFAULT :flock); use constant UPLOAD_DIR = /home/formprof/public_html/cgi-bin/uploads; use constant BUFFER_SIZE = 16_384; use constant MAX_FILE_SIZE = 24_288; #Limit each upload to 1mb use constant MAX_DIR_SIZE = 100 * 524_288; #Limit total uploads to 100mb use constant MAX_OPEN_TRIES = 100; $CGI::DISABLE_UPLOADS = 0; $CGI::POST_MAX = MAX_FILE_SIZE; my $q = new CGI; $q-cgi_error and error( $q, Error tranfering file: . $q-cgi_error); my $file = $q-param( file ) || error( $q, No file received.); my $filename = $q-param( filename ) || error( $q, No filename entered ); my $fh = $q-upload( $file ); my $buffer = ; if ( dir_size( UPLOAD_DIR ) + $ENV{CONTENT_LENGTH} MAX_DIR_SIZE ) { error( $q, Upload directory is full. ); } #Allow letters, digits, periods, underscores, dashes #Convert anything else to an underscore $filename =~ s/[^\w.-]/_/g; if ( $filename =~/^(\w[\w.-]*)/ ) { $filename = $1; } else { error( $q, Invalid file name; files must start with a letter or number.); } #Open output file, making sure the name is unique until ( sysopen OUTPUT, UPLOAD_DIR . $filename, O_CREAT | O_EXCL ) { $filename =~ s/(\d*)(\.\w+)$/($1||0) + 1 . $2/e; $1 = MAX_OPEN_TRIES and error( $q, Unable to save your file. ); } #This is necessary for non-Unix systems; does nothing on Unix binmode $fh; binmode OUTPUT; #Write contents to output file while ( read( $fh, $buffer, BUFFER_SIZE ) ) { print OUTPUT $buffer; } close OUTPUT; sub dir_size { my $dir = shift; my $dir_size = 0; #Loop trough files and sum the sizes; doesn't descend down suddirs opendir DIR, $dir or die Unable to open $dir: $!; while ( readdir DIR ) { $dir_size += -s $dir/$_; } return $dir_size; } sub_error { my( $q, $reason ) = @_; print $q-header( text/html ), $q-start_html( Error ), $q-h1( Error ), $q-p( Your upload was not processed because the following error accured: ), $q-p( $q-i( $reason ) ), $q-end_html; exit; } Thanks Pedro Santos _ ArteVirtual, Exploração de Tecnologias de Informação e Comunicação Pedro Costa Santos,Lda. Rua Barro Branco, Bustelo Apartado 256 3720 Oliveira de Azeméis Tel. (351)256602395 - (351)962836722 www.artevirtual.pt [EMAIL PROTECTED] _ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
What does this error mean?
Hi all, I have the following error: [Wed Apr 17 06:31:08 2002] [error] (26)Text file busy: exec of /var/www/teddy/cgi-bin/test.pl failed What does it mean text file busy? I've just made a test perl file with cat command, gave it the 755 rights, then I used a sync command but it doesn't want to work. The shebang line is ok, and it just prints the Context-type: text/html\n\n; and another line of text. What could be the problem? Thanks. Teddy, [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
re: uploadfile cgi
Oops wrong error this is the error I get from my webserver [Wed Apr 17 04:24:24 2002] [error] [client 217.129.197.231] Premature end of script headers: /home/formprof/public_html/cgi-bin/manage.pl Pedro Santos _ ArteVirtual, Exploração de Tecnologias de Informação e Comunicação Pedro Costa Santos,Lda. Rua Barro Branco, Bustelo Apartado 256 3720 Oliveira de Azeméis Tel. (351)256602395 - (351)962836722 www.artevirtual.pt [EMAIL PROTECTED] _ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
replacing special characters
How do I go about removing characters from a string that are not alpha-numeric, a question-mark, character, or character ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
PERL Programming Standsrds Help : Urgent
HI , I am preparing a standards document for defining the PERL Coding Standards. Any inputs on this will be highly welcome. I will post the document on the list for the benefit of other once completed. Thanks, -Rajnish -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Checking and email address
On 4/15/02 10:38 PM, Timothy Johnson [EMAIL PROTECTED] wrote: I think the preferred way to do a negative match is with the !~ operator. if( $email !~ /@/ ) at this point you don't really need to check if $email eq , because if it does it will not have an @ in it. I'm not sure, but you might also have to escape the @. There's always unless ($email =~ /\@/){ # invalid } else{ # valid. } Of course, that's sort of backwards logic. Regexes do interpolate, so it certainly makes sense to escape the @. I'll point out now that there was a discussion a while back on either [EMAIL PROTECTED], [EMAIL PROTECTED], or [EMAIL PROTECTED] regarding the validation of email addresses, and why it was basically impossible. The best way to validate an email address remains to send an email to the supplied address with a required activation code or the like. That way the user can't use the service until they get their activation code, which is the mailbox of the email address they specified. I'm not sure how valid that is for your situation, though. On 4/15/02 8:50 PM, bob ackerman [EMAIL PROTECTED] wrote: ...regilar expressions... s/regilar/regular/; :P -- Michael -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: PERL Programming Standsrds Help : Urgent
on Tue, 16 Apr 2002 06:39:48 GMT, Rajnish_aggarwal wrote: I am preparing a standards document for defining the PERL Coding Standards. Any inputs on this will be highly welcome. I will post the document on the list for the benefit of other once completed. Did you already try perldoc perlstyle -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
need help with PPM
Dear friends, I started exploring Activestate Perl very recently. And I wanted to install some modules. So I gave the command PPM Search to look for the modules available. But then I get an error message saying there is difficulty in connecting to the URL. I guess i know what the problem is. It could be because we have a Proxy server. So what changes should i do to acheive ppm search successully. If i need to make changes in the environment variables (which environment variables are we talking about) how do i do it ?? I am working on a Windows NT 4.0. Please help me, i feel completely stuck. TIA, Cheers, manoj
Re: replacing special characters
On Apr 16, jon shoberg said: How do I go about removing characters from a string that are not alpha-numeric, a question-mark, character, or character ? You'd probably want to use the tr/// operator. $string =~ tr/a-zA-Z0-9?//cd; That'll remove all characters that are not a-z, A-Z, 0-9, ?, , or . -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: need help with PPM
on Tue, 16 Apr 2002 07:29:49 GMT, Manoj Jacob wrote: I started exploring Activestate Perl very recently. And I wanted to install some modules. So I gave the command PPM Search to look for the modules available. But then I get an error message saying there is difficulty in connecting to the URL. I guess i know what the problem is. It could be because we have a Proxy server. So what changes should i do to acheive ppm search successully. If i need to make changes in the environment variables (which environment variables are we talking about) how do i do it ?? I am working on a Windows NT 4.0. Please help me, i feel completely stuck. ActivePerl comes with extensive HTML documentation, which should be installed in your Start menu.I this documentation you will find a chapter on 'Using PPM'. From the section 'PPM, Proxies and Firewalls', relevant for Windows NT: Right click on My Computer, click on Properties, select the Environment tab. These are your environment settings. Make the following changes: Add the setting HTTP_proxy, with your proxy name as the value (you must include http://;), followed by a colon and the proxy port, if applicable; e.g., http://proxy:8080; If you require a user name and/or password to access your proxy, add the settings HTTP_proxy_user and HTTP_proxy_pass, with your user name and password as the respective values. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Perl License
You might want to do some research on the GPL license and the Artistic License. The upshot of most of these is that you can reuse people's code as long as you give them credit. Technically I think this means that you need to find out who wrote the modules you use. Someone else might have more insight on this. -Original Message- From: Mayank Ahuja To: PERL Sent: 4/15/02 11:12 PM Subject: Perl License Hi Group, I have an application which uses Perl and many modules. The application is like an installer for my other programs (not written in Perl). Since the whole bundle is a commercial package, which all licenses do i need to get for Perl (I heard of something like GNU license). Is it free? Conditions? Can somebody please give me a basic idea and send me link to details? Thanks. -- Regards Mayank The difference between ordinary and extraordinary is that little extra -Anon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: PERL Programming Standsrds Help : Urgent
Standard #1 TIMTOWTDI :) -Original Message- From: Felix Geerinckx To: [EMAIL PROTECTED] Sent: 4/16/02 12:15 AM Subject: Re: PERL Programming Standsrds Help : Urgent on Tue, 16 Apr 2002 06:39:48 GMT, Rajnish_aggarwal wrote: I am preparing a standards document for defining the PERL Coding Standards. Any inputs on this will be highly welcome. I will post the document on the list for the benefit of other once completed. Did you already try perldoc perlstyle -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re:insert in a browseentry
Hi, I have this: opendir(DIR,$_Globals{CDROM}:/DHS3MGR/$tel_version/DHS3Linux); foreach (readdir(DIR)){ unless (/([Comm]+)/){ $box3-insert('end', $_); } $box3 is a browse entry. It works fine but My problem is there is a file under DHS3MGR and not only a directory($tel_version) it didn't work Why? Thanks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
swich user
Hi, i've got a demon i perl that start from root. I would like that after the starting (when starts, does some operation like root), it swiches like other user with low privileges (es. like Apache, starts from root and swiches at www-data). I'm trying the POSIX module, using the function: POSIX::setuid, and POSIX::setgid but nothing. How i can do ?? Thanks Walter -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: insert in a browseentry
Jorge Goncalvez wrote: Hi, I have this: opendir(DIR,$_Globals{CDROM}:/DHS3MGR/$tel_version/DHS3Linux); foreach (readdir(DIR)){ unless (/([Comm]+)/){ $box3-insert('end', $_); } $box3 is a browse entry. It works fine but My problem is there is a file under DHS3MGR and not only a directory($tel_version) it didn't work Why? It is looking the the file name in the current direcory. my $dir = $_Globals{CDROM}:/DHS3MGR/$tel_version/DHS3Linux; opendir DIR, $dir or die Cannot open $dir: $!; foreach ( readdir DIR ) { unless ( /([Comm]+)/ ) { $box3-insert( 'end', $dir/$_ ); } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How use command line parameters?
Many thanks! It works. Johannes Franken wrote: * Ramis [EMAIL PROTECTED] [2002-04-15 22:14 +0200]: I want to get a file name from command line Perl pushes then to a list named @ARGV . So you can access them with any function that operates on lists, like foreach, shift, pop or just $ARGV[n] . How it realizes with several files: somecommand.pl file1,file2... foreach $file (@ARGV) { process($file); } If the files passed as arguments just contain lines of text and you're rather interested in those lines than their filenames, you can also read them from the null filehandle: while () { print got line: $_; } man perlop for more info this. -- Johannes Franken Professional unix/network development mailto:[EMAIL PROTECTED] http://www.jfranken.de/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- ---! My blessing! Ramis. ! ---! http://www.samtan.fromru.com mailto: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: swich user
On Tue, Apr 16, 2002 at 11:30:08AM +0200, walter valenti wrote: Hi, i've got a demon i perl that start from root. I would like that after the starting (when starts, does some operation like root), it swiches like other user with low privileges (es. like Apache, starts from root and swiches at www-data). I'm trying the POSIX module, using the function: POSIX::setuid, and POSIX::setgid but nothing. You don't need the POSIX module, perl can do this on its own. If you take a look at 'perldoc perlvar' and search for UID, you find the following: -- snip -- $REAL_USER_ID $UID $ The real uid of this process. (Mnemonic: it's the uid you came from, if you're running setuid.) -- snip -- What you really should change is the 'Effective User ID': -- snip -- $EFFECTIVE_USER_ID $EUID $ ... (Mnemonic: it's the uid you went to, if you're running setuid.) $ and $ can be swapped only on machines supporting setreuid(). -- snip -- Try the following code snippet: -- snip -- #!/usr/bin/perl use strict; use warnings; $|++; use constant USER = 'nobody'; use constant GROUP = 'nogroup'; my $uid = getpwnam(USER); my $gid = getgrnam(GROUP); print Started as $:$( / $:$)\n; $ = $uid; $) = $gid; print Changed to $:$( / $:$)\n; while (1) { print Still alive...\n; sleep 10; } -- snip -- Here's my session with the code: -- snip -- nijushiho:~# ./snippet [3] 5313 nijushiho:~# Started as 0:0 105 0 / 0:0 105 0 Changed to 0:0 105 0 / 65534:0 105 0 Still alive... Still alive... ps -aef | grep snippet nobody5313 5114 0 13:23 pts/100:00:00 /usr/bin/perl ./snippet root 5315 5114 0 13:24 pts/100:00:00 grep snippet nijushiho:~# kill %3 nijushiho:~# [3]+ Terminated ./snippet nijushiho:~# -- snip -- As you can see, 'snippet' ran as user 'nobody'. Remember that you need to have appropriate permissions to switch users (speak you need to be root). Read Stevens' Advanced Programming in the Unix Environment for *all* the information about this kind of topics. Ask if you need to know more... -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
get PID od existing process
Hi Guru's SYS stuff: perl 5.05 on Tru64 Unix. I am writing a script that needs to find the process IDs of a couple of processes (so they can be killed nicely). Under the csh i would usually do ps -e| grep process. I am not sure if I can do something like this using system or if there is a module that would save a lot of work. I was thinking of doing something like: $output = `system(ps -e)` and doing some regexp on $output. Would that seem like the way to go? Dp. ~~ Dermot Paikkos * [EMAIL PROTECTED] Network Administrator @ Science Photo Library Phone: 0207 432 1100 * Fax: 0207 286 8668 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Read file symbol by symbol?
Friends, how read a file one by one symbols, not a whole string once at time? Thanks. -- ---! My blessing! Ramis. ! ---! http://www.samtan.fromru.com mailto: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: perlcc faq ?
Here is all of it (code, platform, error message). The code is as simple as it gets and it will not compile. Any ideas are welcome. My source: use strict; my $ans=3*12; print 3x12=$ans\n; My platform: Windows XP and Windows 2000. My Perl: v5.6.0 built for MSWin32-x86-multi-thread Binary build 618 I am in directory c:\ and invoke this: perlcc -o z.exe z.pl -- Compiling z.pl: -- Making C(z.pl.c) for z.pl! C:\Perl\bin\Perl.exe -IC:/Perl/lib -IC:/Perl/site/lib -I. -MB::Stash -c z.pl C:\Perl\bin\Perl.exe -IC:/Perl/lib -IC:/Perl/site/lib -I. -MO=C,l2000,-umain,-uattributes,-uDB,-unone,-uWin32,-ustrict z.pl The system cannot find the file specified. ERROR: In generating code for z.pl! -Original Message- From: zentara [mailto:[EMAIL PROTECTED]] Sent: Monday, April 15, 2002 5:48 PM To: [EMAIL PROTECTED] Subject: Re: perlcc faq ? On Mon, 15 Apr 2002 09:47:23 -0400, [EMAIL PROTECTED] (Joe Collins) wrote: Hi, I tried the perlcc process this w/e and I am sure I am using it correctly, i.e. proper parms, good perl program etc but I keep getting a vague error, i.e. the system cannot find the specified file - and it gives NO hint of which file it wants, i.e. .pm, .dll etc? Is there an FAQ for perlcc or cannot someone post some pointers on how to use and pitfalls? What is the exact error message you are getting? There was a bug in one of the 5.6 series of perl that you need to patch to get perlcc to work. I'm not sure if that's your error though. Post the exact error message. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: get PID od existing process
On Tue, Apr 16, 2002 at 12:49:40PM +0100, Dermot Paikkos wrote: Hi Guru's SYS stuff: perl 5.05 on Tru64 Unix. I am writing a script that needs to find the process IDs of a couple of processes (so they can be killed nicely). Under the csh i would usually do ps -e| grep process. I am not sure if I can do something like this using system or if there is a module that would save a lot of work. I was thinking of doing something like: $output = `system(ps -e)` and doing some regexp on $output. Would that seem like the way to go? Yepp, backticking ps is much easier to do portable than using the proc filesystem structures... (Surfing over to search.cpan.org I found Proc::ProcessTable which looks as if it supports a vast variety of different platforms, so you might take look at this too.) But keep in mind that there are still alot of differences in the output of ps among platforms. BTW: it's $output = `ps -e` You don't need the 'system' inside the backquotes. Think about using qx{} instead of the backquote operator if you need to do more complex stuff in the shell. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Checking and email address
If you want to see if a variable contains a @, do what the other suggested. If you want to see if you have (at least) a well formed email address (with optional MX host checking) look at Email::Valid. Cheers, Kevin On Mon, Apr 15, 2002 at 11:58:11PM -0400, Daniel Falkenberg ([EMAIL PROTECTED]) said something similar to: Hello All, How would I go about checking to see if a variable contains an @ symbol? $email = [EMAIL PROTECTED]; if ($email ne @ || $email eq ) { print Please make sure your type your email address in correctly; } else { print All is OK; } Thx, Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- [Writing CGI Applications with Perl - http://perlcgi-book.com] I keep looking for the Crash after viewing X pages settings in Netscape, but I just can't find it. -- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Read file symbol by symbol?
Here is one script I used to inspect files use strict; my $fn; printEnter the name of a file you want to examine ; while () { $fn = $_; last if $fn; } print Opening $fn\n; open TF, $fn or die Cannot open $fn:$!\n; my @ov; my $ov; while (TF) { @ov = unpack('U*',$_); print; print\t\t; foreach $ov (@ov) { print-$ov-; } print \n; } close TF; HTH Ramis [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Friends, how read a file one by one symbols, not a whole string once at time? Thanks. -- ---! My blessing! Ramis. ! ---! http://www.samtan.fromru.com mailto: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
strange cgi error?
hi i have a faulty cgi script which hangs my browser (konq). running the cgi script from a shell shows this first line: Something is wrong?Content-type: text/html so, what is wrong? martin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: grep a array element..
uh... my $lookfor = qr/car/; # this is faster and you don't even need to put in the // -Original Message- From: John Edwards [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 9:42 AM To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED] Subject: RE: grep a array element.. You mean something like this? --- use strict; my @array = qw(car bus caravan bike cart); my $lookfor = car; foreach my $element (@array) { if ($element =~ /$lookfor/) { print Found a match!! = $element\n; } else { print $lookfor doesn't match $element\n; } } --- HTH John The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: question
On Tue, 2002-04-16 at 09:39, Tucker, Ernie wrote: How can a have one perl script call another perl script ? Ernest P. Tucker II Network Technician Charter Communications Madison Management Area (608) 373-7625 That depends on what you mean by call. If you want to run an external script you can use system. If you want to run an external script and want to use the output in your program use the backquotes (@output = `/usr/bin/command.pl`;). However, if you mean that you want to call a function in another script then you need to take a look at modules (perldoc perlmod). -- Today is Sweetmorn the 33rd day of Discord in the YOLD 3168 Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
giving up on perlcc, now trying perl -MO=c z.pl, still hasproble ms
Perlcc.bat seems to difficult at this stage and thus I tried simplifying it. My platform: Windows 2000 or XP My Perl: v5.6.0 built for MSWin32-x86-multi-thread Binary build 618 z.pl: use strict; my $ans=3*12; print 3x12=$ans\n; What I tried: perl -MO=c z.pl The results: Undefined subroutine B::c::compile called at C:/perl/lib/o.pm line 11 BEGIN failed--compilation aborted. Any ideas? I think I am getting closer Joe -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Variable question
On Wed, 2002-04-10 at 11:10, Randal L. Schwartz wrote: Bob == Bob Ackerman [EMAIL PROTECTED] writes: At no point do you have an array in a scalar context, or a list in a scalar context. Really. You don't. Ever. Get it? And why I'm harping on this is that I've seen this myth continue to perpetuate, started from some bad verbage or bad understanding somewhere, and I'm trying to root it out so that it doesn't keep spreading like a bad meme. Bob oooh. i get it. i thought you were overboard, too - until that Bob last go around. you are right. it is subtle, but important. Thank you thank you thank you thank you! It *is* important. Spread the word. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] 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! Sorry for not responding earlier, but illness and Real Work(tm) intervened. Okay, I get it too. The list assignment operator returns the number items copied across, but that still doesn't change how I read it. I read my $var if 0; as $var is a static variable even though it really isn't. I like to assign tags to idioms in my head; in this case static variable and array() in the case of using an empty list assignment operator to get the number of matches in a regex. I don't consider this a bad thing unless you go overboard in thinking that your tag has real meaning. -- Today is Sweetmorn the 33rd day of Discord in the YOLD 3168 Hail Eris, Hack Linux! Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: get PID od existing process
Michael Lamertz: BTW: it's $output = `ps -e` You don't need the 'system' inside the backquotes. Think about using qx{} instead of the backquote operator if you need to do more complex stuff in the shell. It would be better to start using qx() now, it is far more readable. E.g. which is which: my $cmd = `echo Hello World`; my $cmd = 'echo Hello World'; The difference is slight, not enough for someone to read the code easily. Using qx helps, since people generally don't use q/qq - and thus qx stands out better. Also, if it's a really long command line, or some flexibility is required (e.g. you build, or select a command line out of a set) then you are best doing these seperately. E.g. my $cmd = echo Very very long command my $output = qx($cmd); Although you can get away without using brackets, I suggest you always use them. One of few commands that is much easier to read with them. Jonathan Paton __ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: question
If you need to call a function in another Perl script, you must require that script in your program. You can then call the desired function. Make sure the script you wand to require is in the same directory or you will have to push its directory into the @INC array. Here is an example. #!/usr/local/bin/perl -w push(@INC, /usr/home/aaa/); # only needed if someScript.pl is not in the @INC dir, which includes the local dir require 'someScript.pl'; someScriptFunction; Daryl J. Hoyt Performance Engineer Geodesic Systems 312-832-2010 http://www.geodesic.com mailto:[EMAIL PROTECTED] -Original Message- From: Chas Owens [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 9:11 AM To: Tucker, Ernie Cc: [EMAIL PROTECTED] Subject: Re: question On Tue, 2002-04-16 at 09:39, Tucker, Ernie wrote: How can a have one perl script call another perl script ? Ernest P. Tucker II Network Technician Charter Communications Madison Management Area (608) 373-7625 That depends on what you mean by call. If you want to run an external script you can use system. If you want to run an external script and want to use the output in your program use the backquotes (@output = `/usr/bin/command.pl`;). However, if you mean that you want to call a function in another script then you need to take a look at modules (perldoc perlmod). -- Today is Sweetmorn the 33rd day of Discord in the YOLD 3168 Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Need help getting started using hashes
Thank you, David, very much for your solution. With one minor change (use DBD::mysql), it worked perfectly. I am in awe of you ability to do this. I was hoping to use this as a subroutine, to build an array in memory, then to use it repeatedly without rereading the database. Can your solution be used for this? I think your while' loop could be used to build up this structure [I think this is a hash of arrays. Am I correct?], but I'm not sure how to populate it. Thanks, again, for the time you took to help me. -Kevin David Kirol [EMAIL PROTECTED] 04/16/02 11:09AM Kevin, The script below works on my (quickly constructed) approximation of your table/data. It somewhat skirts the issue you mentioned (getting started with hashes) but it may be more to the point. use DBI; use DBD::Mysql; use strict; my $dbname = ; # enter your db name my $host = localhost; my $dbuser = '';# user may be required my $dbpw = ''; # pw may be required my $mscs = dbi:mysql:dbname=$dbname;host=$host;; my $dbh = DBI-connect($mscs, $dbuser, $dbpw) or die Connect fails to $dbname\nError = , DBI::errstr; my $sql = select * from method; my $sth = $dbh-prepare($sql) or die Prepare fails for stmt:\n\t\t$sql\nError = , DBI::errstr; my $rv; unless ($sth-execute) { print\n\tExecute fails for stmt:\n\t\t$sql\nError = , DBI::errstr; $sth-finish; $dbh-disconnect; die \n\t\tClean up finished\n; } print \t\t$rv\n\n if $rv; my %row_ary; my $row_ary; my $key; while ($row_ary = $sth-fetchrow_hashref) { # fetch as a Hash Reference foreach $key (sort keys %$row_ary) {# '%$' is used to dereference the scalar $row_ary to the hash printKey:$key Value $$row_ary{$key}\n; # $$row_ary is part of the deref voodoo } print\n; } $sth-finish; $dbh-disconnect; HTH -Original Message- From: KEVIN ZEMBOWER [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 10:15 AM To: [EMAIL PROTECTED] Subject: Need help getting started using hashes I'm having a hard time understanding and getting started with hashes. I don't think I get the concept, and so can't go from the concept to the actual code. I have a MySQL database table called methods with three fields, methodid, method, and sname. I'd like to read them into a hash, so that I could refer to them there (in memory) rather than repeatedly reading the database. Here's the output of the table: mysql select * from method; +--++-+ | methodid | method | sname | +--++-+ |1 | Combined OCs | COC | |2 | Progestin-Only OCs | POC | |3 | DMPA/NET EN| DMPA| |4 | Norplant Implants | NI | |5 | Female Sterilization | FS | |6 | Vasectomy | Vas | |7 | Condoms| Condoms | |8 | TCu-380A IUD | TCu | |9 | Spermicides| Sperm | | 10 | Diaphragm Cervical Cap | DCC | | 11 | Fertility Awareness-based Methods | FABM| | 12 | Lacational Amenorrhea Method (LAM) | LAM | +--++-+ 12 rows in set (0.01 sec) (I work in the field of reproductive health. Can you tell?) I think I can read in the table with this code, but don't know how to build it into a hash: use DBI; our $dbh = DBI-connect(dbi:mysql:cire:localhost, cire, password, {RaiseError = 1, AutoCommit = 0}) or die; my $method_arrayref = $dbh-selectall_arrayref(SELECT methodid, method, sname FROM method ORDER BY methodid); [Don't know what to do here to build it into a hash, that I can reference by explicitly stating the methodid, then using the method or sname.] Instead of the selectall_arrayref, I can use a while loop and read the table one row at a time, using fetchrow_arrayref, but I still don't know how to use that to build the hash. Would this method be easier? Finally, when I've got the hash built, how can I get a particular method, by specifying it's methodid, or instance? Thanks for your help and suggestions. Please let me know if I should take this question to the DBI-users list. -Kevin Zembower - E. Kevin Zembower Unix Administrator Johns Hopkins University/Center for Communications Programs 111 Market Place, Suite 310 Baltimore, MD 21202 410-659-6139 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: OT: Old uunet gag was Re: How to thread in Perl?
[..] Missile Address: 33:48:3.521N 84:23:34.786W By the way, what is the Missile Address? that is the lattitude and longitude of where the server is suppose to be located - an old habit from the UUNET entries into the UUMAPS - that has held on by some in essence, if you really want to 'do me in' this is the general area to target the missile. In those days of handheld GPS systems, you could easily find someone's neighbourhood using missile addresses. Try this: http://www.mapquest.com/maps/latlong.adp or more precisely: http://www.mapquest.com/maps/map.adp?latlongtype=degreeslatdeg=33latmin=48latsec=3longdeg=-84longmin=23longsec=34 Mental note: Must try this sometime to drop in unexpected to visit somebody you've never met outside of the virtual world :) Jonathan Paton __ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: grep a array element..
On Apr 16, David Gray said: my $lookfor = qr/car/; # this is faster and you don't even need to put in the // if ($element =~ /$lookfor/) { Are you saying the if inside the foreach could be written as: if($element =~ $lookfor) { If the search string is defined with qr//? It doesn't even need to be qr//'d for that to work. The right-hand side of =~ is either a regex or an expression returning a pattern. if ($element =~ generate_random_pattern()) { ... } And using qr// in this case probably won't speed up the code. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: grep a array element..
On Apr 16, Nikola Janceski said: Yes but only if you are looking for that pattern.. if you wanted to add something like sedan then you need to use // but the qr would speed up the compile when using a $var in the //; if($element =~ $lookfor) { ## works if $lookfor = qr/car/; the same as $element =~ /car/ if($element =~ /sedan $lookfor/) { ## works faster if $lookfor = qr/car/; than if $lookfor = car; Sadly, that's misinformation. If the group would like, I can write a post explaining the PURPOSE and APPLICATION of qr// in code. After reading it, you should have a good grasp of when qr// gives speed benefits. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Need help getting started using hashes
David, your revisions made your solution even more clear to me. With regard to my earlier question of using this in a subroutine, I think I now see that %thehash would be my persistent repository for methods, and that I could refer to it just like you did in the last three lines, without rereading the database. Thank you, again, for your help. -Kevin David Kirol [EMAIL PROTECTED] 04/16/02 11:29AM Kevin, Hope the script I sent earlier helped expose you to some of the hash and reference stuff. I re-read your post and it occured to me you requirement was not that complex (but, perl is partly about fun...) Finally, when I've got the hash built, how can I get a particular method, by specifying it's methodid, or instance? Thanks for your help and suggestions. Please let me know if I should take this question to the DBI-users list. This suggests, IMHO, you need to select a key field from the method table and a value field. If you choose id as the key and method as the value you could substitute the code below into the script I sent earlier, and it should be a bit more on target. my %thehash; my @row_ary; my $row_ary; my $key; while (@row_ary = $sth-fetchrow_array) { $key = $row_ary[0]; $thehash{$key} = $row_ary[1]; } $sth-finish; $dbh-disconnect; # all dbi stuff is done, show the hash foreach $key (sort keys %thehash) { printKey: $key Value: $thehash{$key}\n; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: grep a array element..
Please do... I thought using qr// to store REs in variables speed up since it gets compiled once instead of over and over again. -Original Message- From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 11:50 AM To: Nikola Janceski Cc: '[EMAIL PROTECTED]'; Beginners (E-mail) Subject: RE: grep a array element.. On Apr 16, Nikola Janceski said: Yes but only if you are looking for that pattern.. if you wanted to add something like sedan then you need to use // but the qr would speed up the compile when using a $var in the //; if($element =~ $lookfor) { ## works if $lookfor = qr/car/; the same as $element =~ /car/ if($element =~ /sedan $lookfor/) { ## works faster if $lookfor = qr/car/; than if $lookfor = car; Sadly, that's misinformation. If the group would like, I can write a post explaining the PURPOSE and APPLICATION of qr// in code. After reading it, you should have a good grasp of when qr// gives speed benefits. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Read file symbol by symbol?
how read a file one by one symbols, not a whole string once at time? You don't want to, reading one character at a time is VERY slow. At worst, the operating system will cut short your time slot whilst it waits for the file access - perhaps limiting you to a few dozen characters per second... if you care much for that approach, have a look at sysopen/sysread. A better approach is to read a line at a time, and split it down into symbols. However, it's unlikely you actually need to do this in Perl. This works: my @chars = split //, $string; The best approach, is to read fixed sized blocks with sysread and then split into symbols. NB: I said you rarely need to split into symbols, why? Because Perl has one of the most expressive regular expression engine in existance, that does almost all the text manipulation you could ever require. If it's not text manip, I'd like to know what happens to these symbols :) Take care, Jonathan Paton __ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Need help getting started using hashes
Well, I guess I spoke too soon. I still don't understand something. When I execute your program, David, it returns this www:/cire # ./methodtest3.pl Key: 1 Value: Combined OCs Key: 10 Value: Diaphragm Cervical Cap Key: 11 Value: Fertility Awareness-based Methods Key: 12 Value: Lacational Amenorrhea Method (LAM) Key: 2 Value: Progestin-Only OCs Key: 3 Value: DMPA/NET EN Key: 4 Value: Norplant Implants Key: 5 Value: Female Sterilization Key: 6 Value: Vasectomy Key: 7 Value: Condoms Key: 8 Value: TCu-380A IUD Key: 9 Value: Spermicides www:/cire # From the code, I think you're using the first field returned from the database as the key, and the second field as the value, but then discarding the third field. Am I understanding this correctly? I need to be able to recall all three parts of the information as needed. This is why I'm thinking this is a hash of arrays, with the hash key being the methodid, and the hash value being an array of methodid, method and sname. Thanks, again, for all your help. I'm certain my difficulty in understanding is due to my abilities, and not your explanations. -Kevin KEVIN ZEMBOWER [EMAIL PROTECTED] 04/16/02 11:50AM David, your revisions made your solution even more clear to me. With regard to my earlier question of using this in a subroutine, I think I now see that %thehash would be my persistent repository for methods, and that I could refer to it just like you did in the last three lines, without rereading the database. Thank you, again, for your help. -Kevin David Kirol [EMAIL PROTECTED] 04/16/02 11:29AM Kevin, Hope the script I sent earlier helped expose you to some of the hash and reference stuff. I re-read your post and it occured to me you requirement was not that complex (but, perl is partly about fun...) Finally, when I've got the hash built, how can I get a particular method, by specifying it's methodid, or instance? Thanks for your help and suggestions. Please let me know if I should take this question to the DBI-users list. This suggests, IMHO, you need to select a key field from the method table and a value field. If you choose id as the key and method as the value you could substitute the code below into the script I sent earlier, and it should be a bit more on target. my %thehash; my @row_ary; my $row_ary; my $key; while (@row_ary = $sth-fetchrow_array) { $key = $row_ary[0]; $thehash{$key} = $row_ary[1]; } $sth-finish; $dbh-disconnect; # all dbi stuff is done, show the hash foreach $key (sort keys %thehash) { printKey: $key Value: $thehash{$key}\n; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: grep a array element..
To all that help - much appreciated.. Nikola Janceski [EMAIL PROTECTED] on 04/16/2002 04:54:00 PM To: '[EMAIL PROTECTED]' [EMAIL PROTECTED], Nikola Janceski [EMAIL PROTECTED] cc: '[EMAIL PROTECTED]' [EMAIL PROTECTED], Beginners (E-mail) [EMAIL PROTECTED] Subject: RE: grep a array element.. Please do... I thought using qr// to store REs in variables speed up since it gets compiled once instead of over and over again. -Original Message- From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 11:50 AM To: Nikola Janceski Cc: '[EMAIL PROTECTED]'; Beginners (E-mail) Subject: RE: grep a array element.. On Apr 16, Nikola Janceski said: Yes but only if you are looking for that pattern.. if you wanted to add something like sedan then you need to use // but the qr would speed up the compile when using a $var in the //; if($element =~ $lookfor) { ## works if $lookfor = qr/car/; the same as $element =~ /car/ if($element =~ /sedan $lookfor/) { ## works faster if $lookfor = qr/car/; than if $lookfor = car; Sadly, that's misinformation. If the group would like, I can write a post explaining the PURPOSE and APPLICATION of qr// in code. After reading it, you should have a good grasp of when qr// gives speed benefits. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Errors Running Learning Perl in Win32 Scripts
Thanks! I think your advice may apply to the following code that I'm having trouble with: use Win32::NetAdmin; $username = Win32::LoginName; Win32::NetAdmin::UserGetAttributes(, $username, $password, $passwordage, $privilege, $homedir, $comment, $flags, $scriptpath); print The homedir for $username is $homedir\n; Perldoc is your best friend. Try running the command 'perldoc Win32::NetAdmin', which lists the available documentation for the module Win32::NetAdmin that you're using. The example at the end of that listing looks like what you're looking for to get rid of the warnings. I tried this but got similar errors but I played with it and tried to add the other $'s to the print statement but the only thing that will print is the username (I'm logged onto NT Server 4 as Admin). What were the error messages? What exactly did you try? Here's the other code that I'm having trouble with and it's indicative of the problems that I'm having with the IO::Socket::INET-new statement: use IO::Socket; $remote = IO::Socket::INET-new( Proto = tcp; PeerAddr = localhost; PeerPort = daytime(13), ) or die Can't connect to daytime port at localhost; while ($remote) {print} Now, I'm getting syntax errors: syntax error at 415b.pl line 3, near tcp; syntax error at 415b.pl line 7, near ) Any ideas? Remember, I'm a beginner. :-) (no flaming!) One question per thread please. HTH, -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Errors Running Learning Perl in Win32 Scripts
On Tuesday, April 16, 2002, at 09:05 AM, Anthony Beaman wrote: Thanks! I think your advice may apply to the following code that I'm having trouble with: use Win32::NetAdmin; $username = Win32::LoginName; Win32::NetAdmin::UserGetAttributes(, $username, $password, $passwordage, $privilege, $homedir, $comment, $flags, $scriptpath); print The homedir for $username is $homedir\n; I tried this but got similar errors but I played with it and tried to add the other $'s to the print statement but the only thing that will print is the username (I'm logged onto NT Server 4 as Admin). Here's the other code that I'm having trouble with and it's indicative of the problems that I'm having with the IO::Socket::INET-new statement: use IO::Socket; $remote = IO::Socket::INET-new( Proto = tcp; PeerAddr = localhost; PeerPort = daytime(13), ) or die Can't connect to daytime port at localhost; while ($remote) {print} Now, I'm getting syntax errors: syntax error at 415b.pl line 3, near tcp; syntax error at 415b.pl line 7, near ) Any ideas? Remember, I'm a beginner. :-) (no flaming!) you want commas to separate list elements, not semicolons. use IO::Socket; $remote = IO::Socket::INET-new( Proto = tcp, PeerAddr = localhost, PeerPort = daytime(13) ) Thanks! -Original Message- From: David Gray [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 11:38 AM To: [EMAIL PROTECTED]; Anthony Beaman Subject:RE: Errors Running Learning Perl in Win32 Scripts Hi! I have version 5.005_03 and I'm using the Win32 version of the Learning Perl book. I'm having trouble running a few scripts. For example, when I run the following: Exercise 16.1 foreach $host (@ARGV) { ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($host); print $host:\n; foreach $a (@addrs) { print join(., unpack(C4, $a)), \n; } } I get the following errors: Name main::name used only once: possible typo at 415.pl line 5. Name main::length used only once: possible typo at 415.pl line 5. Name main::aliases used only once: possible typo at 415.pl line 5. Name main::addrtype used only once: possible typo at 415.pl line 5. Those aren't errors, they're warnings which get generated because you're (wisely) asking for them by either having a -w at the end of the first line of your program or including the 'use warnings;' pragma somewhere. Your program should run correctly if those are the only messages it generates. What am I doing wrong? The scripts in the book are supposedly for this version but I'm having trouble with this and similar scripts. You shouldn't be declaring those variables as global if you're only going to be using them in that one specific block. You don't even really need to get the values if you're not going to use them. Use instead: my @addrs = (gethostbyname($host))[4]; Hope that helps some, and please ask more specific questions with relevant code attatched if I haven't answered what you were wondering about. -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Writing formatted results to a file
Hi guys I was wondering if you could help me. Does anybody know how to write formatted results to a file ? I am getting the following error : write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, SUMMARYTMP line 5. write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, SUMMARYTMP line 15. write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, SUMMARYTMP line 21. This is the section of my perl code reads results from an BCP output file and is as follows : sub create_summary_report { my (record, $element, $rows_copied, $line_output); record = qw(A B C); $rows_copied = rows copied; $element = 0; open SUMMARYTMP, $bcp_file_directory$log_file_summary_tmp or die Unable to open $log_file_summary_tmp for reading: $!\n; open SUMMARY, $log_directory$log_file_summary_final or die Unable to open $log_file_summary_final for writing: $!\n; print SUMMARY Summary Details\n; print SUMMARY --\n; print SUMMARY Account (From) : $fromAccount\n; print SUMMARY Account (To) : $toAccount\n\n\n; print SUMMARY Record Types\n; print SUMMARY \n; format ADDRESSLABEL = , $record[$element], $line_output .. while(SUMMARYTMP) { chop; $line_output = $_; if ($line_output =~ /\b$rows_copied\b/) { print SUMMARY write(ADDRESSLABEL); $element = $element + 1; } } close SUMMARYTMP or die Error closing $log_file_summary_tmp; close SUMMARY or die Error closing $log_file_summary_final; } I would be most grateful with any advice. Thanks in advance Tony
Looking for an old project
A year or more ago I remember coming across an ongoing project that I'm trying to locate. The basic idea was to implement all of the basic Unix shell commands (e.g. ls, find, cat, etc.) in Perl so as to be used on any platform that was Perl friendly. Has anyone heard of this project, and if so, where is it? thanks, +jeff -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
modules install ...
Hi, I'm using ppm3 on windows to install modules and it works fine, the problem is that the releases I'm looking for aren't available from the 'ActiveState Package Repository' installed after having install activestate. Any idea ??? __ Alain Savio Database administrator direct: +33 (0)4 9238 4148 fax: +33 (0)4 9238 8199 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Writing formatted results to a file
On Tuesday, April 16, 2002, at 10:11 AM, Ho, Tony wrote: Hi guys I was wondering if you could help me. Does anybody know how to write formatted results to a file ? I am getting the following error : write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, SUMMARYTMP line 5. write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, SUMMARYTMP line 15. write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, SUMMARYTMP line 21. This is the section of my perl code reads results from an BCP output file and is as follows : sub create_summary_report { my (@record, $element, $rows_copied, $line_output); @record = qw(A B C); $rows_copied = rows copied; $element = 0; open SUMMARYTMP, $bcp_file_directory$log_file_summary_tmp or die Unable to open $log_file_summary_tmp for reading: $!\n ; open SUMMARY, $log_directory$log_file_summary_final or die Unable to open $log_file_summary_final for writing: $!\n; print SUMMARY Summary Details\n; print SUMMARY --\n; print SUMMARY Account (From) : $fromAccount\n; print SUMMARY Account (To) : $toAccount\n\n\n; print SUMMARY Record Types\n; print SUMMARY \n; format ADDRESSLABEL = @, @ $record[$element], $line_output .. while(SUMMARYTMP) { chop; $line_output = $_; if ($line_output =~ /\b$rows_copied\b/) { print SUMMARY write(ADDRESSLABEL); $element = $element + 1; } } are you trying to send the format to SUMMARY? then i would think you want something like: $~ = ADDRESSLABEL; write(SUMMARY) no 'print SUMMARY ...' check perldoc -f write close SUMMARYTMP or die Error closing $log_file_summary_tmp; close SUMMARY or die Error closing $log_file_summary_final; } I would be most grateful with any advice. Thanks in advance Tony -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Writing formatted results to a file
On Tuesday, April 16, 2002, at 10:11 AM, Ho, Tony wrote: Hi guys I was wondering if you could help me. Does anybody know how to write formatted results to a file ? I am getting the following error : write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, SUMMARYTMP line 5. write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, SUMMARYTMP line 15. write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, SUMMARYTMP line 21. This is the section of my perl code reads results from an BCP output file and is as follows : sub create_summary_report { my (@record, $element, $rows_copied, $line_output); @record = qw(A B C); $rows_copied = rows copied; $element = 0; open SUMMARYTMP, $bcp_file_directory$log_file_summary_tmp or die Unable to open $log_file_summary_tmp for reading: $!\n ; open SUMMARY, $log_directory$log_file_summary_final or die Unable to open $log_file_summary_final for writing: $!\n; print SUMMARY Summary Details\n; print SUMMARY --\n; print SUMMARY Account (From) : $fromAccount\n; print SUMMARY Account (To) : $toAccount\n\n\n; print SUMMARY Record Types\n; print SUMMARY \n; format ADDRESSLABEL = @, @ $record[$element], $line_output .. while(SUMMARYTMP) { chop; $line_output = $_; if ($line_output =~ /\b$rows_copied\b/) { print SUMMARY write(ADDRESSLABEL); $element = $element + 1; } } in addition you need to quote the format label when assigning: $~ = 'ADDRESSLABEL'; close SUMMARYTMP or die Error closing $log_file_summary_tmp; close SUMMARY or die Error closing $log_file_summary_final; } I would be most grateful with any advice. Thanks in advance Tony -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
how to make local variable retain value
If in a subroutine, I have a statements sub { my $local_var=1 $local_var=$local_var+1; } then the next time I run this subroutine, $local_var is reinitialized to 1. However, I would like to have it retain its value from the previous call to the subroutine. For example, if $local_var is 5 at the end of the subroutine call, then it would have this initial value the next time the subroutine is called. This can be done by making $local_var a global variable which I do not want to do. Is there a way to achieve what I am trying to do and still retain $local_var as a local variable, sort of what is called a static variable in C, I think? Thanks, Dick Fell -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Looking for an old project
on Tue, 16 Apr 2002 17:20:36 GMT, Jeff Barrett wrote: A year or more ago I remember coming across an ongoing project that I'm trying to locate. The basic idea was to implement all of the basic Unix shell commands (e.g. ls, find, cat, etc.) in Perl so as to be used on any platform that was Perl friendly. Has anyone heard of this project, and if so, where is it? http://www.perl.com/language/ppt/ -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Writing formatted results to a file
Hi Bob Thanks for the help. I renamed the format label from ADDRESSLABEL to SUMMARY and it appeared to work also. Thanks again for the help. Tony -Original Message- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: 16 April 2002 19:36 To: [EMAIL PROTECTED] Subject: Re: Writing formatted results to a file On Tuesday, April 16, 2002, at 10:11 AM, Ho, Tony wrote: Hi guys I was wondering if you could help me. Does anybody know how to write formatted results to a file ? I am getting the following error : write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, SUMMARYTMP line 5. write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, SUMMARYTMP line 15. write() on closed filehandle main::ADDRESSLABEL at ./test.pl line 2785, SUMMARYTMP line 21. This is the section of my perl code reads results from an BCP output file and is as follows : sub create_summary_report { my (@record, $element, $rows_copied, $line_output); @record = qw(A B C); $rows_copied = rows copied; $element = 0; open SUMMARYTMP, $bcp_file_directory$log_file_summary_tmp or die Unable to open $log_file_summary_tmp for reading: $!\n ; open SUMMARY, $log_directory$log_file_summary_final or die Unable to open $log_file_summary_final for writing: $!\n; print SUMMARY Summary Details\n; print SUMMARY --\n; print SUMMARY Account (From) : $fromAccount\n; print SUMMARY Account (To) : $toAccount\n\n\n; print SUMMARY Record Types\n; print SUMMARY \n; format ADDRESSLABEL = @, @ $record[$element], $line_output .. while(SUMMARYTMP) { chop; $line_output = $_; if ($line_output =~ /\b$rows_copied\b/) { print SUMMARY write(ADDRESSLABEL); $element = $element + 1; } } in addition you need to quote the format label when assigning: $~ = 'ADDRESSLABEL'; close SUMMARYTMP or die Error closing $log_file_summary_tmp; close SUMMARY or die Error closing $log_file_summary_final; } I would be most grateful with any advice. Thanks in advance Tony -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how to make local variable retain value
on Tue, 16 Apr 2002 18:01:28 GMT, Richard Noel Fell wrote: If in a subroutine, I have a statements sub { my $local_var=1 $local_var=$local_var+1; } then the next time I run this subroutine, $local_var is reinitialized to 1. However, I would like to have it retain its value from the previous call to the subroutine. For example, if $local_var is 5 at the end of the subroutine call, then it would have this initial value the next time the subroutine is called. This can be done by making $local_var a global variable which I do not want to do. Is there a way to achieve what I am trying to do and still retain $local_var as a local variable, sort of what is called a static variable in C, I think? Yes, by enclosing the local variable and the subroutine in their own block (and essentially creating a closure): #! /usr/bin/perl -w use strict; { my $static_variable = 1; sub increment { $static_variable++; print Static variable is now $static_variable\n; } } increment(); increment(); -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Errors Running Learning Perl in Win32 Scripts
I did this and I'm now getting the following error: IO::Socket::INET: Unknown error at 415b.pl line 2 Can't connect to daytime port at localhost at 415b.pl line 2. That's what I was getting last night (I changed various things and compiled but got various errors each time). The problem, to me, lies with the IO::Socket::INET statement (correct?). Any ideas? Thanks! -Original Message- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 1:13 PM To: [EMAIL PROTECTED] Subject:Re: Errors Running Learning Perl in Win32 Scripts On Tuesday, April 16, 2002, at 09:05 AM, Anthony Beaman wrote: Thanks! I think your advice may apply to the following code that I'm having trouble with: use Win32::NetAdmin; $username = Win32::LoginName; Win32::NetAdmin::UserGetAttributes(, $username, $password, $passwordage, $privilege, $homedir, $comment, $flags, $scriptpath); print The homedir for $username is $homedir\n; I tried this but got similar errors but I played with it and tried to add the other $'s to the print statement but the only thing that will print is the username (I'm logged onto NT Server 4 as Admin). Here's the other code that I'm having trouble with and it's indicative of the problems that I'm having with the IO::Socket::INET-new statement: use IO::Socket; $remote = IO::Socket::INET-new( Proto = tcp; PeerAddr = localhost; PeerPort = daytime(13), ) or die Can't connect to daytime port at localhost; while ($remote) {print} Now, I'm getting syntax errors: syntax error at 415b.pl line 3, near tcp; syntax error at 415b.pl line 7, near ) Any ideas? Remember, I'm a beginner. :-) (no flaming!) you want commas to separate list elements, not semicolons. use IO::Socket; $remote = IO::Socket::INET-new( Proto = tcp, PeerAddr = localhost, PeerPort = daytime(13) ) Thanks! -Original Message- From: David Gray [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 11:38 AM To: [EMAIL PROTECTED]; Anthony Beaman Subject:RE: Errors Running Learning Perl in Win32 Scripts Hi! I have version 5.005_03 and I'm using the Win32 version of the Learning Perl book. I'm having trouble running a few scripts. For example, when I run the following: Exercise 16.1 foreach $host (@ARGV) { ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($host); print $host:\n; foreach $a (@addrs) { print join(., unpack(C4, $a)), \n; } } I get the following errors: Name main::name used only once: possible typo at 415.pl line 5. Name main::length used only once: possible typo at 415.pl line 5. Name main::aliases used only once: possible typo at 415.pl line 5. Name main::addrtype used only once: possible typo at 415.pl line 5. Those aren't errors, they're warnings which get generated because you're (wisely) asking for them by either having a -w at the end of the first line of your program or including the 'use warnings;' pragma somewhere. Your program should run correctly if those are the only messages it generates.
Re: how to make local variable retain value
On Tue, 2002-04-16 at 14:01, richard noel fell wrote: If in a subroutine, I have a statements sub { my $local_var=1 $local_var=$local_var+1; } then the next time I run this subroutine, $local_var is reinitialized to 1. However, I would like to have it retain its value from the previous call to the subroutine. For example, if $local_var is 5 at the end of the subroutine call, then it would have this initial value the next time the subroutine is called. This can be done by making $local_var a global variable which I do not want to do. Is there a way to achieve what I am trying to do and still retain $local_var as a local variable, sort of what is called a static variable in C, I think? Thanks, Dick Fell You can declare a my variable that doesn't get redefined like this. sub has_a_static_var { #declare a static variable my $static if 0; if (defined $static) { $static++ } else { $static = 0 } #do stuff } N.B. this is bad juju. You might consider using an our variable instead, the downside to that is namespace conflicts. If you define another our variable with the same name they point to the same variable; this is a feature (it is the main difference between our and my). example sub has_an_our_var { our $static; if (defined $static) { $static++ } else { $static = 0 } print \$static in has_an_our_var = $static\n; } The problem occurs when you write another function like this sub has_another_our_var { our $static; if (defined $static) { $static++ } else { $static = 0 } print \$static in has_another_our_var = $static\n; } then these function calls has_an_our_var(); has_another_our_var(); would print $static in has_an_our_var = 1 $static in has_another_our_var = 2 The third option is to use a closure, and there is already a good example of that in another reply. -- Today is Sweetmorn the 33rd day of Discord in the YOLD 3168 Or not. Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Need help getting started using hashes
First let's let the other list member in on the code: use DBI; use strict; my $dbname = test; my $host = localhost; my $dbuser = ''; my $dbpw = ''; my $mscs = dbi:mysql:dbname=$dbname;host=$host;; my $dbh = DBI-connect($mscs, $dbuser, $dbpw) or die Connect fails to $dbname\nError = , $DBI::errstr; my $sql = select * from method; #replace prev. line with: my $sql = 'select methodid,method,sname from method'; $sql .= 'order by methodid'; my $sth = $dbh-prepare($sql) or die Prepare fails for stmt:\n\t\t$sql\nError = , $DBI::errstr; my $rv; unless ($sth-execute) { print\n\tExecute fails for stmt:\n\t\t$sql\nError = , $DBI::errstr; $sth-finish; $dbh-disconnect; die \n\t\tClean up finished\n; } print \t\t$rv\n\n if $rv; my %thehash; my @row_ary; my $row_ary; my $key; while (@row_ary = $sth-fetchrow_array) { $key = $row_ary[0]; $thehash{$key} = $row_ary[1]; #replace prev. two lines with: $ra{$row_ary[0]} = [$row[1], $row[2]]; } $sth-finish; $dbh-disconnect; This builds a hash of n two-element arrays, where n is select count(methodid) from method. You can access the hash using (as the first index) the methodid you want, and the second index will be either 0 or 1, depending whether you want the method or sname (respectively) for that methodid: #based on the table printout from the first post: print $ra-{2}-[0]; # prints 'Progestin-Only Ocs' Print $ra-{2}-[1]; # prints 'POC' The reason I picked a hash of arrays is so it doesn't matter whether there are always as many rows as max(methodid) (i.e. no gaps in the sequence, otherwise you could use an array - see below), and the two-element array because you don't need the associative array functionality. You could just as easily create two local variables ($method,$sname) = (0,1) and access the array using the variables as the index. If you wanted an array of arrays: $ra[$row_ary[0]] = [$row[1], $row[2]]; #based on the table printout from the first post: print $ra-[2]-[0]; # prints 'Progestin-Only Ocs' Print $ra-[2]-[1]; # prints 'POC' Would do the trick. Either way should work, it just depends on how you want to access your data :) check out http://www.perldoc.com/perl5.6.1/pod/perlreftut.html. Hope that helps, -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Errors Running Learning Perl in Win32 Scripts
On Tuesday, April 16, 2002, at 11:18 AM, Anthony Beaman wrote: I did this and I'm now getting the following error: IO::Socket::INET: Unknown error at 415b.pl line 2 Can't connect to daytime port at localhost at 415b.pl line 2. That's what I was getting last night (I changed various things and compiled but got various errors each time). The problem, to me, lies with the IO::Socket::INET statement (correct?). Any ideas? Thanks! the daytime service has to be enabled. usually means uncommenting it in inetd.conf file. usually find it in /etc directory. -Original Message- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 1:13 PM To: [EMAIL PROTECTED] Subject:Re: Errors Running Learning Perl in Win32 Scripts On Tuesday, April 16, 2002, at 09:05 AM, Anthony Beaman wrote: Thanks! I think your advice may apply to the following code that I'm having trouble with: use Win32::NetAdmin; $username = Win32::LoginName; Win32::NetAdmin::UserGetAttributes(, $username, $password, $passwordage, $privilege, $homedir, $comment, $flags, $scriptpath); print The homedir for $username is $homedir\n; I tried this but got similar errors but I played with it and tried to add the other $'s to the print statement but the only thing that will print is the username (I'm logged onto NT Server 4 as Admin). Here's the other code that I'm having trouble with and it's indicative of the problems that I'm having with the IO::Socket::INET-new statement: use IO::Socket; $remote = IO::Socket::INET-new( Proto = tcp; PeerAddr = localhost; PeerPort = daytime(13), ) or die Can't connect to daytime port at localhost; while ($remote) {print} Now, I'm getting syntax errors: syntax error at 415b.pl line 3, near tcp; syntax error at 415b.pl line 7, near ) Any ideas? Remember, I'm a beginner. :-) (no flaming!) you want commas to separate list elements, not semicolons. use IO::Socket; $remote = IO::Socket::INET-new( Proto = tcp, PeerAddr = localhost, PeerPort = daytime(13) ) Thanks! -Original Message- From: David Gray [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 11:38 AM To: [EMAIL PROTECTED]; Anthony Beaman Subject:RE: Errors Running Learning Perl in Win32 Scripts Hi! I have version 5.005_03 and I'm using the Win32 version of the Learning Perl book. I'm having trouble running a few scripts. For example, when I run the following: Exercise 16.1 foreach $host (@ARGV) { ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($host); print $host:\n; foreach $a (@addrs) { print join(., unpack(C4, $a)), \n; } } I get the following errors: Name main::name used only once: possible typo at 415.pl line 5. Name main::length used only once: possible typo at 415.pl line 5. Name main::aliases used only once: possible typo at 415.pl line 5. Name main::addrtype used only once: possible typo at 415.pl line 5. Those aren't errors, they're warnings which get generated because you're (wisely) asking for them by either having a -w at the end of the first line of your program or including the 'use warnings;' pragma somewhere. Your
RE: Need help getting started using hashes
my $sql = select * from method; #replace prev. line with: my $sql = 'select methodid,method,sname from method'; $sql .= 'order by methodid'; #second line should be $sql .= ' order by methodid'; -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Need help getting started using hashes
David Gray, Thanks for the input. Below is another realization using a pseudohash. Some of the code (print stmts at the end) is there to demonstrate concepts (the way your post did). my $sql = select methodid, method, sname from method order by methodid; my $sth = $dbh-prepare($sql) or die Prepare fails for stmt:\n\t\t$sql\nError = , $DBI::errstr; my $rv; unless ($sth-execute) { print\n\tExecute fails for stmt:\n\t\t$sql\nError = , $DBI::errstr; $sth-finish; $dbh-disconnect; die \n\t\tClean up finished\n; } print \t\t$rv\n\n if $rv; my %row_ary; my $row_ary; my $key; my $i = 0; my @array_of_Hrefs; my $href; # The select * from method (above) # and the while loop puts the contents of the # method table into a hash whose key is the # column name and value is the column contents while ($row_ary = $sth-fetchrow_hashref) { $array_of_Hrefs[$i++] = $row_ary; } $sth-finish; $dbh-disconnect; $i = 0; # see Programming Perl page 255 my $phash = \@array_of_Hrefs; for(my $j = 0;$j 12;$j++) { print \n\t\t\t\$j = $j\n\tKey\t\tValue\n; foreach $key ('methodid', 'method', 'sname' ) { print\t$key \t\t$phash-[$j]{$key}; print\n; } } print $phash-[0]{methodid}.\n; print $phash-[1]{method}.\n; print $phash-[3].\n; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Errors Running Learning Perl in Win32 Scripts
Thanks! I can't find the file anywhere and I'm on NT. What would the name of this be (or equivalent) be on NT? Plus, as a FYI, what does this file do? Thanks! -Original Message- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 3:02 PM To: [EMAIL PROTECTED] Subject:Re: Errors Running Learning Perl in Win32 Scripts On Tuesday, April 16, 2002, at 11:18 AM, Anthony Beaman wrote: I did this and I'm now getting the following error: IO::Socket::INET: Unknown error at 415b.pl line 2 Can't connect to daytime port at localhost at 415b.pl line 2. That's what I was getting last night (I changed various things and compiled but got various errors each time). The problem, to me, lies with the IO::Socket::INET statement (correct?). Any ideas? Thanks! the daytime service has to be enabled. usually means uncommenting it in inetd.conf file. usually find it in /etc directory. -Original Message- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 1:13 PM To: [EMAIL PROTECTED] Subject:Re: Errors Running Learning Perl in Win32 Scripts On Tuesday, April 16, 2002, at 09:05 AM, Anthony Beaman wrote: Thanks! I think your advice may apply to the following code that I'm having trouble with: use Win32::NetAdmin; $username = Win32::LoginName; Win32::NetAdmin::UserGetAttributes(, $username, $password, $passwordage, $privilege, $homedir, $comment, $flags, $scriptpath); print The homedir for $username is $homedir\n; I tried this but got similar errors but I played with it and tried to add the other $'s to the print statement but the only thing that will print is the username (I'm logged onto NT Server 4 as Admin). Here's the other code that I'm having trouble with and it's indicative of the problems that I'm having with the IO::Socket::INET-new statement: use IO::Socket; $remote = IO::Socket::INET-new( Proto = tcp; PeerAddr = localhost; PeerPort = daytime(13), ) or die Can't connect to daytime port at localhost; while ($remote) {print} Now, I'm getting syntax errors: syntax error at 415b.pl line 3, near tcp; syntax error at 415b.pl line 7, near ) Any ideas? Remember, I'm a beginner. :-) (no flaming!) you want commas to separate list elements, not semicolons. use IO::Socket; $remote = IO::Socket::INET-new( Proto = tcp, PeerAddr = localhost, PeerPort = daytime(13) ) Thanks! -Original Message- From: David Gray [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 11:38 AM To: [EMAIL PROTECTED]; Anthony Beaman Subject:RE: Errors Running Learning Perl in Win32 Scripts Hi! I have version 5.005_03
More Bidirectional Sockets w/ Win32 Client
I have figured out how to set up bidirectional communication through sockets by forking the server and the client - The client forks just fine under Linux, but if I take the script to Win32 fork doesn't seem to work. This is the code for both the server and client: Here's the server: #!/usr/bin/perl use IO::Socket; $SIG{CHLD} = sub {wait ()}; $main_sock = new IO::Socket::INET (LocalHost= 'shell', LocalPort= 1200, Listen = 5, Proto= 'tcp', Reuse= 1,) or die Couldn't create socket: $!\n; while ($new_sock = $main_sock-accept()) { $pid = fork(); die Cannot fork: $!\n unless defined($pid); if ($pid == 0) { # Child Process while (defined ($buf = $new_sock)) { chomp($buf); print Client said: $buf\n; print $new_sock You said: $buf\n; } exit(0); } } close ($main_sock); And here's the client: #!/usr/bin/perl use IO::Socket; $client = new IO::Socket::INET (PeerAddr = 'shell', PeerPort = 1200, Proto = 'tcp' ) or die Couldn't create socket: $!\n; my $pid = fork(); die Cannot fork\n unless defined $pid; if ($pid) { write_sock(); waitpid($pid, 0); } else { read_sock(); } sub write_sock { for (1 .. 10) { print $client $_\n; } } sub read_sock { while (my $line = $client) { print $line; # report to stdout } } Like I said, this works just fine on Linux-Linux. When the client is Win32 however - it writes to the server just fine, but will just sit there and never read. When I press control-C to escape out of the program, it THEN reads the data from the server. I tried reading into IO::Select to see if that would fix my problem with the client, but I just can't figure it out. Can someone help me with this?? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how to make local variable retain value
On 16 Apr 2002, Chas Owens wrote: sub has_a_static_var { #declare a static variable my $static if 0; if (defined $static) { $static++ } else { $static = 0 } #do stuff } May I ask why you do this if-else thing here? It seems superflous to me. Elias -- There are people who don't like capitalism, and there are people who don't like PCs, but there's no one who likes the PC who doesn't like Microsoft. -- Bill Gates -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Errors Running Learning Perl in Win32 Scripts
On Tuesday, April 16, 2002, at 12:13 PM, Anthony Beaman wrote: Thanks! I can't find the file anywhere and I'm on NT. What would the name of this be (or equivalent) be on NT? Plus, as a FYI, what does this file do? Thanks! daytime service reports the date on port 13 on unix boxes. no, you won't find it on NT. i don't think there is a port setup on NT, so, that code won't work. i guess i suggest trying to run two separate scripts with one as server and one as client and test sending text back and forth. there is a thread now on this list about bidirectional sockets. -Original Message- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 3:02 PM To: [EMAIL PROTECTED] Subject:Re: Errors Running Learning Perl in Win32 Scripts On Tuesday, April 16, 2002, at 11:18 AM, Anthony Beaman wrote: I did this and I'm now getting the following error: IO::Socket::INET: Unknown error at 415b.pl line 2 Can't connect to daytime port at localhost at 415b.pl line 2. That's what I was getting last night (I changed various things and compiled but got various errors each time). The problem, to me, lies with the IO::Socket::INET statement (correct?). Any ideas? Thanks! the daytime service has to be enabled. usually means uncommenting it in inetd.conf file. usually find it in /etc directory. -Original Message- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 1:13 PM To: [EMAIL PROTECTED] Subject:Re: Errors Running Learning Perl in Win32 Scripts On Tuesday, April 16, 2002, at 09:05 AM, Anthony Beaman wrote: Thanks! I think your advice may apply to the following code that I'm having trouble with: use Win32::NetAdmin; $username = Win32::LoginName; Win32::NetAdmin::UserGetAttributes(, $username, $password, $passwordage, $privilege, $homedir, $comment, $flags, $scriptpath); print The homedir for $username is $homedir\n; I tried this but got similar errors but I played with it and tried to add the other $'s to the print statement but the only thing that will print is the username (I'm logged onto NT Server 4 as Admin). Here's the other code that I'm having trouble with and it's indicative of the problems that I'm having with the IO::Socket::INET-new statement: use IO::Socket; $remote = IO::Socket::INET-new( Proto = tcp; PeerAddr = localhost; PeerPort = daytime(13), ) or die Can't connect to daytime port at localhost; while ($remote) {print} Now, I'm getting syntax errors: syntax error at 415b.pl line 3, near tcp; syntax error at 415b.pl line 7, near ) Any ideas? Remember, I'm a beginner. :-) (no flaming!) you want commas to separate list elements, not semicolons. use IO::Socket; $remote = IO::Socket::INET-new( Proto = tcp, PeerAddr = localhost, PeerPort = daytime(13) ) Thanks! -Original Message- From: David Gray [mailto:[EMAIL PROTECTED]] Sent:
Re: how to make local variable retain value
On Tue, 2002-04-16 at 15:51, Elias Assmann wrote: On 16 Apr 2002, Chas Owens wrote: sub has_a_static_var { #declare a static variable my $static if 0; if (defined $static) { $static++ } else { $static = 0 } #do stuff } May I ask why you do this if-else thing here? It seems superflous to me. Elias -- There are people who don't like capitalism, and there are people who don't like PCs, but there's no one who likes the PC who doesn't like Microsoft. -- Bill Gates The idea behind this sub is that $static gets incremented each time you call the subroutine. If that is not what you want then yes, the if-else is not needed. In that case you would want to say something like: sub sub1 { my $static if 0; #this line is not necessary unless you need #a default value for you static variable $static = DEFAULT unless defined $static; #do something } -- Today is Sweetmorn the 33rd day of Discord in the YOLD 3168 Umlaut Zebra über alles! Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how to make local variable retain value
On Tue, Apr 16, 2002 at 03:58:53PM -0400, Chas Owens wrote: The idea behind this sub is that $static gets incremented each time you call the subroutine. If that is not what you want then yes, the if-else is not needed. In that case you would want to say something like: sub sub1 { my $static if 0; #this line is not necessary unless you need #a default value for you static variable $static = DEFAULT unless defined $static; #do something } I just noticed this conversation, so forgive me if this has already been mentioned. The static variable you're using is a misfeature of perl, and could very well disappear or change shape in a future version. I would not suggest relying on this in production code. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Errors Running Learning Perl in Win32 Scripts
Thanks for all of the help. Is the book I'm using (Learning Perl on Win32) a decent book or should I find another? I mean, these scripts were implied to be NT friendly. Also, Should I drop off this list and find a Win32 Beginners list instead since I'm using NT exclusively? Anyone recommend one that's beginner friendly? Thanks for all the help! :-) -Original Message- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 4:01 PM To: [EMAIL PROTECTED] Subject:Re: Errors Running Learning Perl in Win32 Scripts On Tuesday, April 16, 2002, at 12:13 PM, Anthony Beaman wrote: Thanks! I can't find the file anywhere and I'm on NT. What would the name of this be (or equivalent) be on NT? Plus, as a FYI, what does this file do? Thanks! daytime service reports the date on port 13 on unix boxes. no, you won't find it on NT. i don't think there is a port setup on NT, so, that code won't work. i guess i suggest trying to run two separate scripts with one as server and one as client and test sending text back and forth. there is a thread now on this list about bidirectional sockets. -Original Message- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 3:02 PM To: [EMAIL PROTECTED] Subject:Re: Errors Running Learning Perl in Win32 Scripts On Tuesday, April 16, 2002, at 11:18 AM, Anthony Beaman wrote: I did this and I'm now getting the following error: IO::Socket::INET: Unknown error at 415b.pl line 2 Can't connect to daytime port at localhost at 415b.pl line 2. That's what I was getting last night (I changed various things and compiled but got various errors each time). The problem, to me, lies with the IO::Socket::INET statement (correct?). Any ideas? Thanks! the daytime service has to be enabled. usually means uncommenting it in inetd.conf file. usually find it in /etc directory. -Original Message- From: bob ackerman [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 1:13 PM To: [EMAIL PROTECTED] Subject:Re: Errors Running Learning Perl in Win32 Scripts On Tuesday, April 16, 2002, at 09:05 AM, Anthony Beaman wrote: Thanks! I think your advice may apply to the following code that I'm having trouble with: use Win32::NetAdmin; $username = Win32::LoginName; Win32::NetAdmin::UserGetAttributes(, $username, $password, $passwordage, $privilege, $homedir, $comment, $flags, $scriptpath); print The homedir for $username is $homedir\n; I tried this but got similar errors but I played with it and tried to add the other $'s to the print statement but the only thing that will print is the username (I'm logged onto NT Server 4 as Admin). Here's the other code that I'm having trouble with and it's indicative of
RE: Perl CGI with ISP - advice?
These modules you mention, except AnyData::CSV, are in a standard Perl install. As such, if the ISP has Perl installed, they will be there. Go to http://www.scriptsolutions.com/programs/free/perldiver/ and download perldiver. It is free. Place it in the cgi-bin directory (or where ever you plan to run your scripts from) and then just enter its address in the address bar of your browser. It will give you all sorts of good information including a list of all the modules installed on the server. Another good source for a script that does a similar thing is http://www.groundbreak.com/cgiperl/helper.zip. This one will produce links to the CPAN modules associated with the installed modules. In my mind, it is better. Peace In Christ - Ron Goral [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] -Original Message- From: John Brooking [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 3:18 PM To: Beginners CGI Subject: Perl CGI with ISP - advice? Hi, I'm writing a Perl-based system to allow simple site content management through web forms. I'm a relative beginner to both Perl and CGI, although I have much experience with C, Visual Basic, and relational database programming. The system I'm writing is targeted to non-profits and small businesses, the kinds of outfits which typically will have sites hosted by an ISP, not on their own hardware with their own people to administer it. So my software will need to be (1) small, and (2) installable to a virtual domain cgi-bin path by FTP with normal owner permissions, not system admin and/or shell access. I've found that this cuts down on available technology quite dramatically. One hesitation I have is that most Perl modules assume that you can run an install procedure to install the module in your system. If an outfit has only FTP access to its virtual domain, not shell access or sysadm privilege, the only thing you can do is copy the module's files over from some other place you've installed them (such as my PC's hard drive). This seems to be working with two of the modules I've used so far (HTML::Template and AnyData::CSV), but I'm hesitant to rely too much on a lot of them. Obviously, you run a risk if a module has platform-specific functionality. I'm particularly shy of CGI.pm, both due to size and also uncertainty of if it can be installed by a simple file copy. I'd appreciate any advice anyone could give on the difficulties I might encounter in this endeavor, in particular module size and ability to install on an ISP-hosted virtual domain by FTP alone. Should I be convincing the ISP to install the modules in their /site/lib instead, rather than us putting them in our virtual domain? Is CGI.pm recommended in this situation? Any other issues you would foresee me having? (I already know I'll have to think through security at some point.) Thanks in advance for any replies. - John Brooking - Do You Yahoo!? Yahoo! Tax Center - online filing with TurboTax -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
localtime help
Can someone point me to the perldoc's that can help me get the localtime equivalent of the shell command /bin/date +'%Y%m%d' ? Thanks! -James James Kelty Sr. Unix Systems Administrator Everbase Systems 541.488.0801 [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Errors Running Learning Perl in Win32 Scripts
From:bob ackerman [EMAIL PROTECTED] daytime service reports the date on port 13 on unix boxes. no, you won't find it on NT. I don't have NTs by hand by on Win2k Pro : c:\ telnet localhost 13 11:08:28 PM 4/16/2002 Connection to host lost. But you have to enable/install Simple TCP/IP Services service. I believe it was available in WinNT as well, though the name might have been a bit different. From: Anthony Beaman [EMAIL PROTECTED] Thanks for all of the help. Is the book I'm using (Learning Perl on Win32) a decent book or should I find another? I mean, these scripts were implied to be NT friendly. I believe it usualy is. In this case they should have added a note on what has to be enabled on the computer for the example to function. Also, Should I drop off this list and find a Win32 Beginners list instead since I'm using NT exclusively? Anyone recommend one that's beginner friendly? Thanks for all the help! :-) No. There is a lot of people using Windows on this list so there's no need to look for any other. Except maybe you might want to subscribe to some of the mailing lists provided by ActiveState : http://aspn.activestate.com/ASPN/Mail/ Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: localtime help
On Apr 16, James Kelty said: Can someone point me to the perldoc's that can help me get the localtime equivalent of the shell command /bin/date +'%Y%m%d' ? Either perldoc -f localtime and roll your own, or read perldoc POSIX and look for strftime(). It uses the same format strings as date, I believe. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: localtime help
From: James Kelty [EMAIL PROTECTED] Can someone point me to the perldoc's that can help me get the localtime equivalent of the shell command /bin/date +'%Y%m%d' ? I believe you are looking for perldoc POSIX Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
setuid ing perl?
I used perl -MCPAN -e shell to install new perl modules. I now also have perl 5.6.1 (I had 5.6.0) But I am afraid that my perl does not support setuid anymore. How can I simply reinstall perl, but then with setuid support using CPAN? Henk -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Errors Running Learning Perl in Win32 Scripts
Anthony Beaman wrote: Hi! I have version 5.005_03 and I'm using the Win32 version of the Learning Perl book. I'm having trouble running a few scripts. For example, when I run the following: Exercise 16.1 foreach $host (@ARGV) { ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($host); print $host:\n; foreach $a (@addrs) { print join(., unpack(C4, $a)), \n; } } I get the following errors: Name main::name used only once: possible typo at 415.pl line 5. Name main::length used only once: possible typo at 415.pl line 5. Name main::aliases used only once: possible typo at 415.pl line 5. Name main::addrtype used only once: possible typo at 415.pl line 5. What am I doing wrong? The scripts in the book are supposedly for this version but I'm having trouble with this and similar scripts. Also, I cannot get the IO::Sockets::INET-new line to work in any of my scripts to run (Unknown Error). Any advice? Thanks! :-) Change this line ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($host); To (undef, undef, undef, undef, @addrs) = gethostbyname($host); John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Looking for an old project
Hi, Probably have PPT (Perl Power Tools) project in mind? Check under scripts directory at CPAN. Alfred Vahau Project Breeze SNPS UniPNG -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: setuid ing perl?
On Tue, Apr 16, 2002 at 11:27:50PM +0200, Henk-Jan wrote: I used perl -MCPAN -e shell to install new perl modules. I now also have perl 5.6.1 (I had 5.6.0) This was a bug with older versions of the CPAN shell. What version of the shell are you running? I'd suggest upgrading it, so that module upgrades don't try to upgrade perl. But I am afraid that my perl does not support setuid anymore. How can I simply reinstall perl, but then with setuid support using CPAN? You must be mistaken, 5.6.1 supports setuid. How did you go about determining it doesn't? Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Errors Running Learning Perl in Win32 Scripts
Change this line ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($host); To (undef, undef, undef, undef, @addrs) = gethostbyname($host); I think mine is prettier, at least (see below)... Is there a reason why this might be considered Better than doing: @addrs = (gethostbyname($host))[4]; ? -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Errors Running Learning Perl in Win32 Scripts
From: David Gray [EMAIL PROTECTED] Change this line ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($host); To (undef, undef, undef, undef, @addrs) = gethostbyname($host); I think mine is prettier, at least (see below)... Is there a reason why this might be considered Better than doing: @addrs = (gethostbyname($host))[4]; ? Of course there is. Those two are different. Notice that the fifth variable in the list is not a scalar but an array. It is supposed to slurp all items starting with the fifth. While usually the gethostbyname() will return only one address it may return several. At least according to the docs. Example: sub foo { (0,1,2,3,4,5,6,6,8,9) }; (undef,undef,undef,undef,@a1) = foo(); @a2 = (foo())[4]; print join(, , @a1),\n; print join(, , @a2),\n; Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Net::SFTP installation on Windows
How can I install Net::SSH and Net::SFTP on ActivePerl (Windows NT), please? Your help will be appreciated so much. Thanks, Ahmed -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Errors Running Learning Perl in Win32 Scripts
Change this line ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($host); To (undef, undef, undef, undef, @addrs) = gethostbyname($host); I think mine is prettier, at least (see below)... Is there a reason why this might be considered Better than doing: @addrs = (gethostbyname($host))[4]; ? Of course there is. Those two are different. Notice that the fifth variable in the list is not a scalar but an array. It is supposed to slurp all items starting with the fifth. While usually the gethostbyname() will return only one address it may return several. At least according to the docs. Example: sub foo { (0,1,2,3,4,5,6,6,8,9) }; (undef,undef,undef,undef,@a1) = foo(); @a2 = (foo())[4]; print join(, , @a1),\n; print join(, , @a2),\n; Oh, hehe, right... Silly me! -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Meaning
As I am somewhat new to perl can someone tell me what this means $header = qq~ I understand the header but what is the qq~ for? Thanks
Re: Definition
On Tue, 2002-04-16 at 19:48, Bill Lyles wrote: As I am somewhat new to perl can someone tell me what this means $header = qq~ I understand the header but what is the qq~ for? Thanks qq sets up the character to use in place of . Your code probably looks like this $header = qq~ this has both types of quotes (' and ) and several lines ~ Also lose the background image for list serv posts (Jade Falcons always got their butts handed to them by Clan Wolf anyways). -- Today is Sweetmorn the 33rd day of Discord in the YOLD 3168 This statement is false. Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: OT: Old uunet gag was Re: How to thread in Perl?
Is there a way to know the Missile Address from an IP address? -- Ahmed Moustafa http://pobox.com/~amoustafa -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Counting pairs in a hash.
All, What is the simplest way to find out how many pairs I have in a hash? I am putting a variable number in when reading data from a file, and I then need to split the file in half for display. Thx, Glenn.
Re: Counting pairs in a hash.
On Apr 16, Glenn Cannon said: What is the simplest way to find out how many pairs I have in a hash? Use the keys() function. $nkeys = keys %hash; -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Peeking into a return list was - Re: Errors Running Learning Perl in Win32 Scripts
On Tuesday, April 16, 2002, at 04:15 , David Gray wrote: Another INSANE, but actually useful, illustration from Jenda: { how does he pop them out? } Example: sub foo { (0,1,2,3,4,5,6,6,8,9) }; (undef,undef,undef,undef,@a1) = foo(); @a2 = (foo())[4]; print join(, , @a1),\n; print join(, , @a2),\n; Oh, hehe, right... Silly me! -dave p0: given that few hosts are 'double/multi homed' such that they will actually return multiple IP_ADDR - the cheat is not a bad idea. # As long as you comment it that way. p1: hence it follows that picking out a given scalar from a return in the form my $one_answer = (funkCall(@argList))[$thatArg] ; is actually a COOL idea for all of those my ($var1, $var2, $j, $k, ) = funk_with_large_list_return(@argList) ; where you only wanted the one element... # as long as appropriately commented p2: So I thought I would posit the following: #!/usr/bin/perl -w use strict; sub foo { my @list = (0,1,2,3,4,5,6,6,8,9) ; my @front = qw/bob fred alice 2/; return( @front, \@list ); } my (undef,undef,undef,undef,@a1) = foo(); my @a2 = (foo())[4]; print join(, , @a1),\n; print @a2 \n; which I thought would pass the @list though and mostly gets me there but: vladimir: 73:] ./jenda.pl ARRAY(0x1273c4) ARRAY(0x135534) vladimir: 74:] so I know it's an ARRAY - how do I get into it? ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: setuid ing perl?
On Tue, Apr 16, 2002 at 11:27:50PM +0200, Henk-Jan wrote: I used perl -MCPAN -e shell to install new perl modules. I now also have perl 5.6.1 (I had 5.6.0) This was a bug with older versions of the CPAN shell. What version of the shell are you running? I'd suggest upgrading it, so that module upgrades don't try to upgrade perl. It is too late now But I am afraid that my perl does not support setuid anymore. How can I simply reinstall perl, but then with setuid support using CPAN? You must be mistaken, 5.6.1 supports setuid. How did you go about determining it doesn't? I want to install a scipt called openwebmail. If I run it as root, it works allright (I see html code coming) If I run it as a user I get: ./openwebmail/pl' must be setuid to root This is what is says in the faq: http://turtle.ee.ncku.edu.tw/openwebmail/doc/faq.txt Q: I got Internal server error when running Open WebMail? I got can not do setuid error? I got Software error: Can't locate etc/openwebmail.conf in @INC error? A: There are many possible answers... 1. Please check you have installed a complete set of perl 5.005 or above. And You uncompress the openwebmail-1.xx.tgz with proper parameter. It should be tar -zxvBpf openwebmail-1.xx.tgz 2. Your openwebmail scripts may have wrong owner or mode. The permission of openwebmail.pl, openwebmail-main.pl, openwebmail-read.pl, openwebmail-viewatt.pl, openwebmail-send.pl, openwebmail-spell.pl, openwebmail-prefs.pl, openwebmail-folder.pl and checkmail.pl should be mode=4555 owner=root group=mail 3. Your perl may be compiled with suid ability disabled. a. check if you have a executable of suidperl, then 'chmod 4555 suidperl' and change #!/usr/bin/perl to the path of this suidperl b. Or recompile your perl with suid enabled Here are the steps: 1. grab the perl source tar ball 2. sh Configure -de (de means default perl config) 3. edit config.sh and set this : d_dosuid='define' d_suidsafe='undef' 4. then make, make install (make suidperl if needed) (thanks to Nemo Kaiser, [EMAIL PROTECTED]) c. Or use uty/suidwrap.pl to generate C wrappers for all suid scripts. Here are the steps: 1. cd cgi-bin/openwebmail 2. perl uty/wrapsuid.pl /fullpath/cgi-bin/openwebmail All suid scripts will be renamed to .scriptname.pl and the C wrapper will be generated and named as script.pl (thanks to Chris Heegard, [EMAIL PROTECTED]) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Counting pairs in a hash.
I'm sure there is a better way, but you could do it this way: foreach(keys %hash){ $count++; } print $count keys.\n; -Original Message- From: Glenn Cannon To: [EMAIL PROTECTED] Sent: 4/16/02 7:20 PM Subject: Counting pairs in a hash. All, What is the simplest way to find out how many pairs I have in a hash? I am putting a variable number in when reading data from a file, and I then need to split the file in half for display. Thx, Glenn. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: need help with PPM
Hi Felix and Timothy and others, Thank you very much for your advice. I have done the required. unfortunately as the machine i have installed Perl is on the Server of our workplace, i am unable to do a restart. Is restarting after assigning the HTTP_proxy variable essential or should the problem be solved without a restart. I am still unable to connect to the URL ppm is trying to connect when i do ppm search. It gives me a message: Error connecting to 'http;//ppm.Activestate.com/cgibin/PPM/ppmserver.pl?urn:/PPM Server'. I am still stuck with this...please help anyone. Cheers manoj -Original Message- From: Felix Geerinckx [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 16, 2002 1:07 PM To: [EMAIL PROTECTED] Subject: Re: need help with PPM on Tue, 16 Apr 2002 07:29:49 GMT, Manoj Jacob wrote: I started exploring Activestate Perl very recently. And I wanted to install some modules. So I gave the command PPM Search to look for the modules available. But then I get an error message saying there is difficulty in connecting to the URL. I guess i know what the problem is. It could be because we have a Proxy server. So what changes should i do to acheive ppm search successully. If i need to make changes in the environment variables (which environment variables are we talking about) how do i do it ?? I am working on a Windows NT 4.0. Please help me, i feel completely stuck. ActivePerl comes with extensive HTML documentation, which should be installed in your Start menu.I this documentation you will find a chapter on 'Using PPM'. From the section 'PPM, Proxies and Firewalls', relevant for Windows NT: Right click on My Computer, click on Properties, select the Environment tab. These are your environment settings. Make the following changes: Add the setting HTTP_proxy, with your proxy name as the value (you must include http://;), followed by a colon and the proxy port, if applicable; e.g., http://proxy:8080; If you require a user name and/or password to access your proxy, add the settings HTTP_proxy_user and HTTP_proxy_pass, with your user name and password as the respective values. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to check installed Modules in perl
Dear All, I am new to perl. I would like to know what can I do to check whether I have installed particular module in perl. Thanks Alex