RE: Split function in Perl
http://search.cpan.org/~nwclark/perl-5.8.7/lib/Text/ParseWords.pm -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Michael Louie Loria Sent: Monday, July 25, 2005 9:57 PM To: perl-win32-users@listserv.ActiveState.com Subject: Split function in Perl -BEGIN PGP SIGNED MESSAGE- Hash: SHA512 Hello, I have a problem with the split function. string - - - one "two three" "four five" six seven should be split to - - - one two three four five six seven string - - - one two three four five six seven should be split to - - - one two three four five six seven the difference is the string enclosed with " " is considered as 1 string even with spaces. Thanks, Michael Louie Loria -BEGIN PGP SIGNATURE- Comment: Public Key: https://www.biglumber.com/x/web?qs=0x4A256EC8 Comment: Public Key: http://www.lorztech.com/GPG.txt Comment: Yahoo ID: michaellouieloria iQEVAwUBQuZ7drXBHi2y3jwfAQqL6QgAiROSQrYOyuoITOPNsSxdtYT4VLDeEy6u LFGQlEcdX2b4nkcPkmNcOEbt6qlnWHjnhQwODEH34+BjIpgAb/7yrIxmlQRPnmnj /4O4x0YnFa71Gl7jUwythyv3gDeBo12x6GA+SZU/sdNL0IbDGu1qe0aXxEL7dt0I kveNDhglPqihuWmAG6cqb0CatkV9na9Fg/whsfHbwIGPY4fYCSPi7GzXT+M/K0Mi yGslp31ibW4ZVWtDm+v6g8dV4RFiKfSSpk8c65S7i384vU0RdhdPMu6Qww2U4PYa yKdLLZ49XTG7AbMHiF/r6VUMf8rUJ0vE0I83uH1hAGI+x40K2tqiag== =icS0 -END PGP SIGNATURE- Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: comparing floating point numbers
'eq' is a string comparison verses '==' which is numeric. Perl appears to be applying some rounding when it converts the number to a string before printing. Make the bottom of you code look like this: if ($sum1 == $sum2) { print("EQUAL\n"); } else { print("NOT EQUAL\n"); printf "sum1: %30.20f\n", $sum1; printf "sum2: %30.20f\n", $sum2; } The output is this: sum1 = -237.15 sum2 = -237.15 NOT EQUAL sum1: -237.15568434 sum2: -237.149997726263 Read the introduction to chapter 2 of the Perl Cookbook, 2d Ed and recipes 2.2 and 2.3. for idea of how to deal with this. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of John Deighan Sent: Sunday, July 24, 2005 3:07 PM To: perl-win32-users@listserv.ActiveState.com Subject: re: comparing floating point numbers At 02:20 PM 7/24/2005, Ed Chester wrote: >John Deighan:: > > Is there a safe way to compare 2 floating point numbers in Perl? [snip] > > My debugger says that they're both '630.24' [snip] > > However, the == test fails and the != test succeeds > >can you post code with the comparison == that fails ? >if the debugger says they're the same, they're very very probably the same. >are you sure the variable (or whatever) you're giving to == are >really what you >want them to be? >there are lots of ways to compare numbers, right down to looping over the bits >and logically >XNORing them. Sorry about the lack of sample code, but I know that people who work with floating point numbers know about this problem, and I was wondering what the best solution was. Here is sample code with output. Note that I'm not formatting the output or rounding or anything - just printing out the contents of the 2 variables. my $sum1 = -237.15; my $sum2; $sum2 += -26.35; $sum2 += -26.35; $sum2 += -26.35; $sum2 += -26.35; $sum2 += -26.35; $sum2 += -26.35; $sum2 += -26.35; $sum2 += -26.35; $sum2 += -26.35; print("sum1 = $sum1\n"); print("sum2 = $sum2\n"); if ($sum1 == $sum2) { print("EQUAL\n"); } else { print("NOT EQUAL\n"); } OUTPUT: sum1 = -237.15 sum2 = -237.15 NOT EQUAL ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: help with getting file stats
Have you tried stat ("$dir/$file")? If you just stat ($file), $file would have to be the full path or a file in the current directory. Do you have a sample output you could share? -Dgg -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of lorid Sent: Wednesday, July 20, 2005 3:34 PM To: perl-win32-users Subject: help with getting file stats I am trying to get the file stats I found this code in ch8 of perl cookbook ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks ) = stat($filename) and read the man page for stat and perlfunc but cant seem to get a simple program to get the file stats after reading the man page for stat I thought my problem might be that I need to use fstat since the file may be open but that doesnt seem to work either any suggestions would be appreciated. my simple test program: #!/usr/local/bin/perl use File::stat; my $dir_ctr = 0; my $file_ctr = 0; my $dir = "/home/lorid/wrccpics"; print "Opening $dir \n"; opendir DH, $dir or die "Can't open the current dir $!\n"; while($file = readdir(DH)){ if(-d "$dir/$file"){ print "\n Dir: $file \n"; $dir_ctr++; } elsif(-e "$dir/$file"){ print "\nFile: $file \n"; ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks ) = stat($file); print "\n $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,Mtime: $mtime,\n Ctime:$ctime,\n $blksize, $blocks\n"; $file_ctr++; } } print "\n"; print "number of directories: $dir_ctr"; print "\n"; print "number of files: $file_ctr"; print "\n"; ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: using strict
If you are just getting one array back, that is a feature of Perl. It doesn't delineate between the end of one array and the start of another in a list of arguments. The first array in the returned arguments will encompass all remaining values. If you reverse the order of the arguments, you will get the first return value in $counter, the second returned value in $Value2, and anything else in @Value1. -Dgg -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jim Hansen Sent: Thursday, April 07, 2005 5:05 PM To: perl-win32-users@listserv.ActiveState.com Subject: using strict How strict is 'struct' when it comes to passing data to and from sub routines and how do you do that? I have a subroutine that counts items, then returns to the calling program, but even when I set return like return(@Value1,$Value2,$counter); the calling program does not have the information. Thanks __ Yahoo! Messenger Show us what our next emoticon should look like. Join the fun. http://www.advision.webevents.yahoo.com/emoticontest ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Can't print to screen | STDOUT messed up?
Title: Message Exactly what are the commands you are using to run this script? Is this from the DOS prompt or in the cygwin bash shell? What is the output that you are getting if anything? Tnx -Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Earthlink-m_ryanSent: Tuesday, March 01, 2005 12:44 PMTo: perl-win32-users@listserv.ActiveState.comSubject: Can't print to screen | STDOUT messed up? Has anyone ever accidentally changed the stdout for perl to nowhere. I can't print anything to the screen from the command prompt with -#! /usr/bin/perl-wuse strict;print "Hello world. \n";exit;result = ""I run perl 5.6 on a windoze machine, this is the first time I've ever seen this.I checked the last few programs that I ran with perl and can't find anything that would have changed any environment variables.Does anyone know what I might have messed up, or how I could debug this problem . I have tested several programs. I have also run a program that prints to a file without any problems. I ran perldoc on '-q output' and that printed out to the screen without any problems as well. Isn't perldoc run with perl.exe too? So, why does it print to the screen? I can't understand this at all. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: How to use "#! perl " to directly run perl script on Win32platform?
I do something similar to the 'she-bang' line with a section of Windows script statements that reads the Perl script from the remainder of the file. The section below goes ahead of the Perl statements and the script is saved as a .cmd or .bat file. -Cut Here--- @rem = '--*-Perl-*-- @echo off if "%OS%" == "Windows_NT" goto WinNT perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 goto :EOF :WinNT perl -x -S %0 %* if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto :EOF if %errorlevel% == 9009 echo You do not have Perl in your PATH. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul goto :EOF @rem '; #!perl #line 15 eval 'exec F:\Programs\perl561\bin\perl.exe -S $0 ${1+"$@"}' if 0; # Your favorite Perl statements go after this line. -Cut Here--- This is a slight variation of what I have seen several other scripts use including the ppm.bat, perldoc.bat, etc that is distributed with ActiveState. The only difference is that I use 'goto :EOF' which is a generic return statement rather then 'goto endofperl'. Using 'goto endofperl' requires that the last line of you file be a label ':endofperl'. -Dgg -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Friday, January 21, 2005 5:13 AM To: honery wu Cc: perl-win32-users@listserv.ActiveState.com Subject: Re: How to use "#! perl " to directly run perl script on Win32platform? Hi Honery, normally if you install active perl, you just have to double-click the perl script in the explorer, or type at the prompt in the 'DOS'- window. If you don't see a little yellow pearl as icon for the .pl files, you probably didn't associate .pl with perl.exe during the install. You can do this manually by right-clicking on one of your .pl files, choose 'Properties', then select 'open' or 'open with...' and 'choose program'. If the Perl Command Line Interpreter is not in the list of file shown then, hit the 'Browse...' button and go to '/bin' and choose 'perl.exe'. Be sure to tick the checkbutton 'Always use the selected program for this kind of files'. After that, the above said possibilities should work. On older windows systems a reboot might be necessary. Regards, Gerhard |-+-> | | | | | | | | | | | | | | | | |honery wu <[EMAIL PROTECTED]> | | | | | |Sent by: | | |[EMAIL PROTECTED]| | |.com | | | | | |2005-01-21 11:33 AM | | |Please respond to honery wu | | | | |-+-> >--- | | | | To: perl-win32-users@listserv.ActiveState.com | | cc: (bcc: Gerhard Petrowitsch/STN/SC/PHILIPS) | | Subject:How to use "#! perl " to directly run perl script on Win32platform? | | | | Classification: | | | | | >--- | Hello , Could you please tell me how to use "#! perl " to directly run perl script on Win32 platform? Assume that ActivePerl has installed in "c:\perl" . Any help will be appreciated. Thxs, Honery. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Random?
>From "Programming Perl", 3rd Edition: 29.2.119. rand rand EXPR rand This function returns a pseudorandom floating-point number greater than or equal to 0 and less than the value of EXPR. (EXPR should be positive.) If EXPR is omitted, the function returns a floating-point number between 0 and 1 (including 0, but excluding 1). rand automatically calls srand unless srand has already been called. See also srand. To get an integral value, such as for a die roll, combine this with int, as in: $roll = int(rand 6) + 1; # $roll now a number between 1 and 6 Because Perl uses your own C library's pseudorandom number function, like random(3) or drand48(3), the quality of the distribution is not guaranteed. If you need stronger randomness, such as for cryptographic purposes, you might consult instead the documentation on random(4) (if your system has a /dev/random or /dev/urandom device), the CPAN module Math::TrulyRandom, or a good textbook on computational generation of pseudorandom numbers, such as the second volume of Knuth.[10] [10] Knuth, D.E. The Art of Computer Programming, Seminumerical Algorithms, vol. 2, 3d ed. (Reading, Mass.: Addison-Wesley, 1997). ISBN 0-201-89684-2. >From this, srand is already being used behind the scenes. You may be stuck with going to 'Math::TrulyRandom' or roll-your-own. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Eric Germann Sent: Monday, October 11, 2004 6:22 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: Random? srand () is your friend -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Monday, October 11, 2004 7:03 PM To: [EMAIL PROTECTED] Subject: Random? Hello everybody, i did this: for($x=0;$x<100;$x++) { $c=rand((100)); if(length($c)<6) { $rnd{$c}++; } } foreach $rnd (keys %rnd) { print qq($rnd{$rnd} x $rnd\n); } which produced this: 29 x 62500 33 x 15625 30 x 93750 27 x 31250 23 x 0 30 x 46875 29 x 78125 which confused me a bit, because every time I ran my prog it was pretty much the same :( 35 x 15625 33 x 62500 30 x 93750 34 x 31250 39 x 0 34 x 46875 31 x 78125 and it becomes even worse when I use a higher numb for rand(). This raises some questions... 1. Why does perl behave that way? 1a. Is perl alright, and it's me who behaves strange? 2. How can i counteract this? - My ultimate goal is to get real random numbers between 0 and 10... For any reply - thanks in advance :) Harry PS: I tried to install math::trulyrandom from CPAN but thar behaves strange too. Always tells me, that some .h-File is missing. :( - But maybe it's me again... ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Time::HiRes problems
What do you get if you get the time as an array using gettimeofday? A difference would indicate it is a problem in the conversion of the system time format to a floating point format. The following is the relevant comment for the perldoc (see NOTE 2): time () Returns a floating seconds since the epoch. This function can be imported, resulting in a nice drop-in replacement for the time provided with core Perl; see the "EXAMPLES" below. NOTE 1: This higher resolution timer can return values either less or more than the core time(), depending on whether your platform rounds the higher resolution timer values up, down, or to the nearest second to get the core time(), but naturally the difference should be never more than half a second. NOTE 2: Since Sunday, September 9th, 2001 at 01:46:40 AM GMT, when the time() seconds since epoch rolled over to 1_000_000_000, the default floating point format of Perl and the seconds since epoch have conspired to produce an apparent bug: if you print the value of Time::HiRes::time() you seem to be getting only five decimals, not six as promised (microseconds). Not to worry, the microseconds are there (assuming your platform supports such granularity in first place). What is going on is that the default floating point format of Perl only outputs 15 digits. In this case that means ten digits before the decimal separator and five after. To see the microseconds you can use either printf/sprintf with "%.6f", or the gettimeofday() function in list context, which will give you the seconds and microseconds as two separate values. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Leigh Sharpe Sent: Tuesday, June 15, 2004 7:28 PM To: [EMAIL PROTECTED] Subject: Time::HiRes problems Hi all, I'm having some problems with the time reported by Time::HiRes::time(). I'm working on a non-blocking ping application, and using the system time to calculate round-trip-times. Basically, what I'm doing is: $start_time=time; send a ping. Do some other stuff look for a response. If one is there, $end_time=time; $round_trip_time=$end_time-$start_time; However, for any round trip times less than 10 mS, I am getting the same value in $end_time as $start_time. Some of these pings are returning in about 2-3 mS, but my script reports it as 0. Printing $start_time and $end_time gives the same values in each variable. Pings over 10mS work fine. Any idea what I'm doing wrong? Regards, Leigh Leigh Sharpe Network Systems Engineer Pacific Wireless Ph 9584 8966 Mob 0408 009 502 email [EMAIL PROTECTED] web www.pacificwireless.com.au ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Screen Capture Desktop as Service
This is not a solution so much as part of the analysis: Services are non-interactive processes as opposed to a logged in user is an interactive process. What do you expect to see on the desktop of a non-interactive session? If it is non-interactive, do you have a desktop? -Dgg -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Roy Huggins Sent: Tuesday, April 27, 2004 7:28 PM To: [EMAIL PROTECTED] Subject: Screen Capture Desktop as Service Hola. After Randy Kobes very kindly helped me get a working copy of Win32::Screenshot, I have been testing using it in a script running as a service. It is pretty essential that I be able to run this app as a service. The difficulty is that Win32::Screenshot always seems to grab it's shot from the logged-in user's desktop, not from the service's desktop. There is one XS function that performs all the heavy lifting, whcih I have included the text of at the end of this message. Does anyone know of any way that I can create an environment in which Win32::Screenshot will regard the service's desktop as the location to retrieve it's image from rather than the logged-in user's desktop? Can anyone shoot me down if they know for sure that one cannot get a graphical image of a desktop that is owned by a service? Thanks very much! -Roy Huggins XS function CaptureHwndRect(), which does the actual capturing for Screenshot.pm: XS(XS_Win32__Screenshot_CaptureHwndRect); /* prototype to pass -Wmissing-prototypes */ XS(XS_Win32__Screenshot_CaptureHwndRect) { dXSARGS; if (items != 5) Perl_croak(aTHX_ "Usage: Win32::Screenshot::CaptureHwndRect(handle, xx, yy, ww, hh)"); SP -= items; { HWND handle = (HWND)SvIV(ST(0)); LONG xx = (LONG)SvIV(ST(1)); LONG yy = (LONG)SvIV(ST(2)); LONG ww = (LONG)SvIV(ST(3)); LONG hh = (LONG)SvIV(ST(4)); #line 292 "Screenshot.xs" HDC hdc; HDC my_hdc; HBITMAP my_hbmp; BITMAPINFO my_binfo; long bufferlen; LPVOID buffer; int out; long i; long *p; #line 587 "Screenshot.c" #line 303 "Screenshot.xs" hdc = GetDC(handle); /* create in-memory bitmap for storing the copy of the screen */ my_hdc = CreateCompatibleDC(hdc); my_hbmp = CreateCompatibleBitmap(hdc, ww, hh); SelectObject(my_hdc, my_hbmp); /* copy the part of screen to our in-memory place */ BitBlt(my_hdc, 0, 0, ww, hh, hdc, xx, yy, SRCCOPY); /* now get a 32bit device independent bitmap */ ZeroMemory(&my_binfo, sizeof(BITMAPINFO)); /* prepare a buffer to hold the screen data */ bufferlen = hh * ww * 4; buffer = (LPVOID) safemalloc(bufferlen); /* prepare directions for GetDIBits */ my_binfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); my_binfo.bmiHeader.biWidth = ww; my_binfo.bmiHeader.biHeight = -hh; /* negative because we want top-down bitmap */ my_binfo.bmiHeader.biPlanes = 1; my_binfo.bmiHeader.biBitCount= 32; /* we want RGBQUAD data */ my_binfo.bmiHeader.biCompression = BI_RGB; if(GetDIBits(my_hdc, my_hbmp, 0, hh, buffer, &my_binfo, DIB_RGB_COLORS)) { /* Convert RGBQUADs to format expected by Image::Magick .rgba file (BGRX -> RGBX) */ p = buffer; for( i = 0 ; i < bufferlen/4 ; i++ ) { *p = ((*p & 0x00ff) << 16) | ((*p & 0x00ff) >> 16) | (*p & 0xff00) | 0xff00; p++; } EXTEND(SP, 3); PUSHs(sv_2mortal(newSViv(my_binfo.bmiHeader.biWidth))); PUSHs(sv_2mortal(newSViv(abs(my_binfo.bmiHeader.biHeight; PUSHs(sv_2mortal(newSVpvn((char*) buffer, bufferlen))); out = 1; } else { out = 0; } safefree(buffer); DeleteDC(my_hdc); ReleaseDC(handle, hdc); DeleteObject(my_hbmp); if ( out == 1 ) { XSRETURN(3); } else { XSRETURN_NO; } #line 638 "Screenshot.c" PUTBACK; return; } } --- Outgoing mail has been scanned for viruses by AVG. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.668 / Virus Database: 430 - Release Date: 4/25/2004 ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Blocking While Reading the Network
This is my first attempt to write a network client to test my server. So far it looks good except that the amount of writing to STDERR I do during debugging seems to effect how long it takes to read the first buffer of data. The section of code is as follows: Cut Here #warn "request: ",$request_string; $$self{CONNECTION}->send($request_string); #warn " ( getting the response )"; my ($rebuild, $message, $buffer, $done); $$self{CONNECTION}->recv($buffer,12000); # <- delay is here #warn "read: ",$buffer; ($message, $buffer, $done) = Sirsi::Utilities::DeChunk($buffer); #warn sprintf ("\n%s|%s|%s",$message, $buffer, $done); until ( $done ) { while ( length ($buffer) ) { ($rebuild, $buffer, $done) = Sirsi::Utilities::DeChunk($buffer); #warn sprintf ("\n%s|%s|%s",$rebuild, $buffer, $done); $message .= $rebuild; } unless ( $done ) { $$self{CONNECTION}->recv($buffer,12000); #warn "read: ",$buffer; ($rebuild, $buffer, $done) = Sirsi::Utilities::DeChunk($buffer); #warn sprintf ("\n%s|%s|%s",$rebuild, $buffer, $done); $message .= $rebuild; } } #warn "\nmessage: ",$message; Cut Here Depending on the 'warn' statements that are un-commented, the 'recv' command may take a second to a minute or two to respond. Sometimes adding a message increases the delay. Sometimes it is shorter. I am testing the code on Active State Perl 5.6.1 running on WinXP. Is there something I should be doing to clear the buffer, or select a file handle, or something to correct this? Tnx, Dgg Darrell Gammill System Support Specialist [EMAIL PROTECTED] ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Private Variables in OOP
I would say you need to make 'hair' part of the object's attributes stored in the hash. sub hair { my ($) = @_; $s->{hair} = "brown"; } sub name { my ($s) = @_; printf "%s:%s\n", $s->{PERSON}, $s->{hair}; } -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jeremy A Sent: Friday, April 09, 2004 5:37 PM To: [EMAIL PROTECTED] Subject: Private Variables in OOP Hi all, I have an perl oop problem. I want to manipulate/set a variable for one instance of an object without changing the same variable for all instances of an object. Thanks in advance for any help, Regards, Jeremy A. --- here is some a script which, when executed, demonstrates my problem. my $n = Test->new( PERSON => "jer"); my $g = Test->new(PERSON => "jon"); while(1) { $g->name(); $n->name(); $g->hair(); <--- this changes $hair var for both $g and $n objects, but i want it to only change for $g. } package Test; use strict; use warnings; my $hair = "n/a"; sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = { 'PERSON' => undef, @_, }; return bless $self, $class; } sub hair { $hair = "brown"; } sub name { my ($s) = @_; print $s->{PERSON},":$hair\n"; } 1; ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: What is wrong with this?
These were the data elements on the end of the input lines. You might do something a chomp before the push to strip off the EOL marker. -Original Message- From: steve silvers [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 12, 2003 8:53 AM To: [EMAIL PROTECTED] Subject: What is wrong with this? I don't understand why the output of the below snippet kind of blows up.. --TEXT FILE test.txt-- 03|04|09|14|15|18|24|27 09|23|24|26|27|28|33|35 10|11|13|15|17|18|19|22 07|08|13|17|22|23|24|25 03|06|07|08|11|12|16|17 02|05|06|09|12|18|19|22 --SCRIPT #!Perl -w use strict; use vars qw(%counts $numbers @numbers); open(FILE,"test.txt") || die "Can't open file $^E"; while() { push(@numbers, split(/\|/,$_)); } close(FILE); # - # Get Count.. $counts{$_}++ foreach @numbers; foreach (sort { $counts{$b} <=> $counts{$a} } keys %counts) { print qq( $_ - $counts{$_} \n); } -- RESULTS -- 18 - 3 24 - 3 09 - 3 07 - 2 23 - 2 15 - 2 08 - 2 17 - 2 19 - 2 03 - 2 11 - 2 12 - 2 13 - 2 06 - 2 22 - 2 22 - 1 25 - 1 17 - 1 35 - 1 27 - 1 02 - 1 05 - 1 16 - 1 33 - 1 04 - 1 26 - 1 10 - 1 14 - 1 27 - 1 28 - 1 Why do the last numbers as it seems is blowing out and not keep a nice form like the rest of the results? It seems likes it's just the last numbers? 22 - 1 25 - 1 17 - 1 35 - 1 27 - 1 Any suggestions Steve _ MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. http://join.msn.com/?page=features/virus ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs