- Nagios - Switch Interface Traffic
- How To - Linux Server Performance
- Notes - Building New ESXi Host for iSCSI with Jumbo Frames
- Microsoft Office Version Numbers (XP, 2003, 2007, 2010)
- ESXi Custom Welcome Screen Text
- PHP - Read Data from a CSV file
- PHP - Input Variables from URL
- Fix - WMI Error EventID 10
- Fix - EventID 4007 DNS Server Error
- FIX - CHECK_ESX3.PL Script
Perl Split Function Example
- References:
The perl split function is handy for breaking up a string into several values. For example if you are reading lines from a file and want to split that line into some different values, manipulate them, and spit them into a new file. If you're lucky, the line is delimited by something like a ^ (carrot) charcater.
So, source line is something like:
larry^moe^curly
You can use a one liner like this to break up the line into 3 values...
($value1,$value2,$value3)=split(/\^/,$line);
Note how we had to escaple the ^ with a backslash. So now ...
print "$value1 --- $value2 --- $value3";
will print "larry --- moe --- curly". If there were numbers, you can quickly read in a data file, calculate some values and spill out a new results file. Or split a string into component values to be used later... be creative!
- Printer-friendly version
- Login to post comments
-
