Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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.

You can Add a comment or ranking to this page

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