Training, Open Source
computer languages


PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
question

Posted by yamaha102 (yamaha102), 3 March 2008
Hi,
I am using the data::dumper (advice from KevinAD last few posts) Thanks.

Currently i have a problem.
Code as below...

...
$rawdata = &process($data);
print Dumper($rawdata );
exit;
....

result as following: (from the command prompt)
$VAR1 = [
         '2CHAC25700C',
         '2CHAC28500B',
         '2CHAC28500D',
         '2CHAC20000A',
         '2CHAC20000F',
         '2CHAC27000C',
         '2CHAC27000E',
         '2CHAC27200E',
         '2CHAC26200B',
        ]

_______________________

well, i wish to edit the $rawdata to 8 charcter instead of eleven, which i hope to get
$VAR1 = [
         '2CHAC257',
         '2CHAC285',
         '2CHAC285',
         '2CHAC200',
         '2CHAC200',
         '2CHAC270',
         '2CHAC270',
         '2CHAC272',
         '2CHAC262',
        ]

thus i edit the code as follwoing:
...
$rawdata = &process($data);
$rawdata =substr($rawdata ,0,8 );
print Dumper($rawdata);
exit;
...

but  what i get was something as below:
VAR1 ='ARRAY<0X|';


Please guide. Thanks




Posted by KevinAD (KevinAD), 3 March 2008
Your $rawdata looks to be a reference to an array. So you have to loop through the array and truncate the data:


for (@{$rawdata}) {
  $_ = pack("A8");
}


pack() should be faster than substr()  but you could use substr if thats what you prefer. Look up the pack() function for details.



Posted by yamaha102 (yamaha102), 4 March 2008
thx.
another question
i wish to eliminate the duplicate entry after the pack function.
..something as below:
$VAR1 = [
         '2CHAC257',
         '2CHAC285',  
         '2CHAC200',
         '2CHAC270',
         '2CHAC272',
         '2CHAC262',
        ]

________________________________

for (@{$gdata_raw}) {
$_ = grep { !$seen{$_}++;} $_;
}

but i get the output as


$VAR1 = [
         1,
         0,  
         0,
         0,
         1,
         1,
        ]


Posted by KevinAD (KevinAD), 4 March 2008
You should really look up the functions on perldoc or your local install of perl.

grep returns a list, so you don't want to assign the return value of grep to a scalar, and in this case you don't want to use a loop, because grep loops through all the data you want it to search:

@new_data = grep{! $seen{$_}++} @rawdata;

In the code I posted earlier, this line:

  $_ = pack("A8");

should be:

  $_ = pack("A8",$_);

Posted by yamaha102 (yamaha102), 4 March 2008
thank you so much.

Posted by yamaha102 (yamaha102), 4 March 2008
thank you so much.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.


WELL HOUSE CONSULTANTS LTD.: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho