473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Trying to get to values from each line in a file

154 100+
Hi I am trying to get to values on each line of a text file and write to another file
I am still new to this I tried to writing the following below

Just to let you know i am still a newbie.

Expand|Select|Wrap|Line Numbers
  1.  #!/usr/bin/perl
  2.  
  3. user warnings;
  4. use strict;
  5. use Fcntl; 
  6.  
  7. $OD = "filehandle";
  8. $filepath = "myorders.txt";
  9. my @line = open(OD, $FilePath) or die "file could not be opened"; 
  10.  
  11. $line  = <OD>;
  12.       print $line;
  13. close OD;
  14.  
  15.  
  16. for $line (<OD>){
  17.  
  18. $i = "1";
  19. $a = ($line);
  20.  
  21. #This is how the line looks like####
  22. # Line 1 contains:#
  23. #  D30002115964000080000200US      NXLS000000014888320070110200701090000000000000005                                - 00000000                                                                                20061345000000001USA     000000.05                NN        00000000 #
  24. # I am trying to get what is underlined#
  25.  
  26. $info = 'substr($a 5 6 7 8 9 10 11 12)';
  27.  
  28. print "$info";
  29. $quantity = 'substr($a 80 81)';
  30.  
  31. print "$quantity"
  32.  
  33. sysopen(HTML, 'myvalues.txt', O_RDWR|O_EXCL|O_CREAT, 0755);
  34. printf  HTML "$info"     "$quantity \n"
  35. close(HTML);
  36. $i++
  37.  
  38. }; 
Dec 12 '06 #1
3 1856
GunnarH
83
Hmm.. Suggested reading:

perldoc perlintro

perldoc -f open

perldoc -f substr
Dec 12 '06 #2
I recommend pack/unpack, Perl's answer to "packed data streams" like the one you just described. Here's a little program to get the first part:

Expand|Select|Wrap|Line Numbers
  1. #!/bin/perl
  2.  
  3. $sample_line = "D30002115964000080000200US";
  4.  
  5. @ary = unpack "A4A8A*", $sample_line;
  6.  
  7. print "$ary[0]\n";
  8. print "$ary[1]\n";
  9. print "$ary[2]\n";
  10.  
When you run this program, you'll get:

Expand|Select|Wrap|Line Numbers
  1. D300
  2. 02115964
  3. 000080000200US
  4.  
Do a perldoc -f pack, and a perldoc -f unpack. Better, get yourself the Perl Cookbook, which has a good recipe for understanding this function. Or Google around for a pack/unpack tutorial. Good luck!
Dec 16 '06 #3
jonathan184
154 100+
Excellent thanks guys the perl doc links you guys sent are great and the unpak and pack great way to start it off thank you.

I appreciate it.
Dec 16 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Rich Grise | last post by:
I think I've finally found a tutorial that can get me started: http://www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html and I've been lurking for awhile as well. What happened is,...
0
by: renateves | last post by:
My problem is that i have a xml file that is convert into a table (by xsl) in a aspx file, and in vb code i want to get and put some values to the table. Is the code: ASPX FILE <Get the...
13
by: scorpion53061 | last post by:
Very urgent and I am very close but need a little help to get me over the edge........ I need to write these columns to a html file with each row containing these columns (seperated by breaks)....
4
by: Jim in Arizona | last post by:
This doesn't make any sense to me. I'm hoping some SQL guru out there knows the answer. I'm making a help desk type database system. There's only two tables, one called TTickets and the other...
1
by: Ty Moffett | last post by:
I am trying to write a little app that will perform unattended installations of various software packages. I have a text file, each line is a string containing the complete command to start a...
3
by: cuneyt | last post by:
Hi I am working on a class that reads parameter values from a configuration file and inserts them into a hash. There are many good dimplementations of this on the Web. What I would like to do,...
1
by: David | last post by:
I have rows of 8 numerical values in a text file that I have to parse. Each value must occupy 10 spaces and can be either a decimal or an integer. // these are valid - each fit in a 10 character...
3
by: Max58kl | last post by:
Trying to access data and print it to the screen using Perl Builders I/O Window -------------------------------------------------------------------------------- Hi I am using a program called...
3
by: hutch75 | last post by:
Question could also be asked, how to compare data between two arrays and perform an action (print cmd) everytime there is a match? The problem I'm having with the code below is that the comparison...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.