Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › (SOLVED) perl: parsing data?
New Posts  All Forums:Forum Nav:

(SOLVED) perl: parsing data?

post #1 of 3
Thread Starter 
im noob, im trying to pars a file but can't figure it out. reading some examples i found the following. what's wrong?
Code:
#!/usr/bin/perl
 open (FILE, 'data.txt');
 while (<FILE>) {
        chomp;
        print "$_\n";
 }
 close (FILE);

im getting the following errors:
Code:
./read.pl: line 2: syntax error near unexpected token `FILE,'
./read.pl: line 2: ` open (FILE, 'data.txt');'

in the same dir as the script i have a file called "data.txt" that contains,
Code:
stuff
morestuff
dBag
(9 items)
 
yep...
(10 items)
 
air
(8 items)
 
CPUMotherboardRAMHard Drive
xeon e3-1230v2 supermicro mbd x9scm-0 KVR1333D3E9S/4G OCZ vertex3 60GB 
CoolingOSPowerCase
1u 80mm blower + passive cpu  proxmox 3.1 supermicro 300w 1u supermicro 1u 
Other
2x intel pro1000 nics  
CPUMotherboardGraphicsRAM
A8-3870K @ 3.7GHz GIGABYTE A75M-UD2H Power Cooler 7870 Team Group Inc 
Hard DriveCoolingOSPower
3x OCZ Agility 3 60GB (RAID-0 on Rocket RAID 27... Corsair H-80 core win-7 Seagate 750 Gold 
CaseAudio
some lian-li case... M-Audio AV40s + 10" Sony ___? 
CPUMotherboardGraphicsRAM
D525 @ 1.8GHz Supermicro onboard 2x2GB DDR1333 
Hard DriveOSCaseOther
WD Green ubuntu 12 1u  3x40mm fans  
  hide details  
Reply
dBag
(9 items)
 
yep...
(10 items)
 
air
(8 items)
 
CPUMotherboardRAMHard Drive
xeon e3-1230v2 supermicro mbd x9scm-0 KVR1333D3E9S/4G OCZ vertex3 60GB 
CoolingOSPowerCase
1u 80mm blower + passive cpu  proxmox 3.1 supermicro 300w 1u supermicro 1u 
Other
2x intel pro1000 nics  
CPUMotherboardGraphicsRAM
A8-3870K @ 3.7GHz GIGABYTE A75M-UD2H Power Cooler 7870 Team Group Inc 
Hard DriveCoolingOSPower
3x OCZ Agility 3 60GB (RAID-0 on Rocket RAID 27... Corsair H-80 core win-7 Seagate 750 Gold 
CaseAudio
some lian-li case... M-Audio AV40s + 10" Sony ___? 
CPUMotherboardGraphicsRAM
D525 @ 1.8GHz Supermicro onboard 2x2GB DDR1333 
Hard DriveOSCaseOther
WD Green ubuntu 12 1u  3x40mm fans  
  hide details  
Reply
post #2 of 3
you're nearly there:
Code:
#!/usr/bin/perl
open (FILE, '<data.txt');
while (<FILE>) {
       chomp;
       print "$_\n";
}
close (FILE);

You were missing the greater than or less than sign (used to denote whether you're reading from, or writing to data.txt

Also, you don't need chomp in that exercise:
Code:
#!/usr/bin/perl
open (FILE, '<data.txt');
while (<FILE>) {
       print "$_";
}
close (FILE);
post #3 of 3
Thread Starter 
REP+
dBag
(9 items)
 
yep...
(10 items)
 
air
(8 items)
 
CPUMotherboardRAMHard Drive
xeon e3-1230v2 supermicro mbd x9scm-0 KVR1333D3E9S/4G OCZ vertex3 60GB 
CoolingOSPowerCase
1u 80mm blower + passive cpu  proxmox 3.1 supermicro 300w 1u supermicro 1u 
Other
2x intel pro1000 nics  
CPUMotherboardGraphicsRAM
A8-3870K @ 3.7GHz GIGABYTE A75M-UD2H Power Cooler 7870 Team Group Inc 
Hard DriveCoolingOSPower
3x OCZ Agility 3 60GB (RAID-0 on Rocket RAID 27... Corsair H-80 core win-7 Seagate 750 Gold 
CaseAudio
some lian-li case... M-Audio AV40s + 10" Sony ___? 
CPUMotherboardGraphicsRAM
D525 @ 1.8GHz Supermicro onboard 2x2GB DDR1333 
Hard DriveOSCaseOther
WD Green ubuntu 12 1u  3x40mm fans  
  hide details  
Reply
dBag
(9 items)
 
yep...
(10 items)
 
air
(8 items)
 
CPUMotherboardRAMHard Drive
xeon e3-1230v2 supermicro mbd x9scm-0 KVR1333D3E9S/4G OCZ vertex3 60GB 
CoolingOSPowerCase
1u 80mm blower + passive cpu  proxmox 3.1 supermicro 300w 1u supermicro 1u 
Other
2x intel pro1000 nics  
CPUMotherboardGraphicsRAM
A8-3870K @ 3.7GHz GIGABYTE A75M-UD2H Power Cooler 7870 Team Group Inc 
Hard DriveCoolingOSPower
3x OCZ Agility 3 60GB (RAID-0 on Rocket RAID 27... Corsair H-80 core win-7 Seagate 750 Gold 
CaseAudio
some lian-li case... M-Audio AV40s + 10" Sony ___? 
CPUMotherboardGraphicsRAM
D525 @ 1.8GHz Supermicro onboard 2x2GB DDR1333 
Hard DriveOSCaseOther
WD Green ubuntu 12 1u  3x40mm fans  
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › (SOLVED) perl: parsing data?