473,395 Members | 1,639 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,395 software developers and data experts.

Writing to a file

Hi,
I am trying to simply write the results of my grep etc to a file.
According to what I read in books, I need to open the ouput file with ">" to overwrite or ">>" to append. And then use that filehandle in the print command
open (IN , "$file") or die "unable to open file";

Expand|Select|Wrap|Line Numbers
  1. #Find the lines in the file containing word 'hardware' #
  2. while (<IN>) {
  3.         if ($num < 30 ) {
  4.         @hardware_line = grep (/hardware/, $_);
  5.         print "@hardware_line\n";
  6.     }
  7.  
  8. #-----------------------------------------------------#
  9. # Get just the hardware address from the whole line in the file
  10. #-----------------------------------------------------#
  11.      foreach my $word (@hardware_line) {
  12.          @hardware1 = split /\s+/, $word;
  13.          $hardware = $hardware1[3];
  14.          open (OUT, ">$out_file1") or die "unable to open output file";
  15.          print OUT $hardware;
  16.          close OUT or die "$!";
  17.      }
I am gettng following error.

Use of uninitialized value in concatenation (.) or string at search_IP_02.plx for line in BOLD
unable to open output file at search_IP_02.plx line for line in BOLD

Any comments?
M
Nov 30 '06 #1
3 1495
GunnarH
83
Did you read the error message before you posted here? It tells you pretty clearly what the problem is...

Another thing is that this part of your code makes little sense to me:
Expand|Select|Wrap|Line Numbers
  1. while (<IN>) {
  2.         if ($num < 30 ) {
  3.         @hardware_line = grep (/hardware/, $_);
  • What purpose does the $num variable serve?
  • Why are you using the grep() function?
  • What do you think that @hardware_line contains after the while loop is finished?
Nov 30 '06 #2
1. The input file is huge and just to keep the search limited to first few (30 lines) of the file while debugging, I have used if ($num < 30) Thats the only purpose of $num. I will take it out when I am finished. (I have fogotten to paste the line $num++; and also the } for the while loop. But they exist in my code.

2. The file contains lines like :

hardware ethernet 00:11:23:45:67:23

What I am trying to do by using grep and @hardware_line is finding all such lines. And then picking up only the third element that is the actual mac address by using

$hardware = $hardware1[3];

3. I still do not understand the error I am getting

Thanks
M
Dec 1 '06 #3
I worked on the code and I understood what the error was. Thanks!
Dec 1 '06 #4

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

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
3
by: ishekar | last post by:
Hi, I have an application where i want to write data to a file, the data is being sent from an external source. I know the total size of the data and then i retrieve the data in small segments...
1
by: Daniel | last post by:
System.IO.StreamWriter Close or Flush method to shut down the computer in such a way that just part of the file is written? or an empty file is written? Also if the Close or Flush is to a...
2
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
4
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will...
0
by: Yunus's Group | last post by:
Yunus's Group May 23, 3:36 pm show options Newsgroups: microsoft.public.dotnet.languages.vb From: "Yunus's Group" <yunusasm...@gmail.com> - Find messages by this author Date: 23 May 2005...
16
by: Claudio Grondi | last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want to change only eight bytes in this file at a given offset of appr. 200 Gbyte (all other data in that file should remain...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
3
by: Barry Flynn | last post by:
Hi I am working with a VB 2005 program which has been converted from VB6. It writes data out to a flat file, with code like the following line WriteLine(riFileNo, "Hist", lsAssetID,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.