I see where you have tried to adopt some of what I have done but there are some points that you are missing.
Let's start here:
At the top you are trying to open a file, and you appear to want to "READ" it because you try to set $dnafile with the filehandle. However your method is a slightly off, to read is "<", if writing (">") you would not try to GET content from the file into a variable (unless using read & write ("+<" or "+>").
should be something more like (if reading the file):
The open function is easiest to use when you stick to the 3 argument form. Also, when using a variable, you should escape the "$" symbol in the open function...
Taken from perldoc.org:
Quote:
open($fh, ">", \$variable) || ..
While that is not to say "only" takes 3 arguments, it is most often used that way. You can read more on that function at: Perl Doc - Open Function
The "or die $!" says if we couldn't open the file, exit with the error that was returned while trying to open it. The "$!" variable contains the actual error that was returned to perl from the OS. You will want to see that error not "Could't open file". A generic error message is confusing and makes debugging very hard. The actual error will be more helpful in tracking down errors.
I suggest changing to this style for the rest of your file operations as well.
The errors you see are are actually correct because you try to use "COUNTBASE" which is the file handle (not the file name or even the file itself) AFTER you have closed it.
Given that as a start, I am not sure exactly what you are trying to do with that section of code.
Consider this code: RESULTS:
Now consider this code (more like yours):
RESULTS:
That code is not what you want, you have type cast "data" as a string not an array!
Because of this you only managed to get the first line into the string variable.
What I think you wanted was something more like this though...
RESULTS:
Last edited by ddreggors; 06-12-2012 at 10:32 PM..
Hello all
im facing some kind of problem i have this string :
functionA() $" "$ functionB("arg1") $" = "$
i will like to replace all the pairs of opening and closing "$" to be something like that
functionA() <#" "#> functionB("arg1") <#" = "#>
i cant of course do is with simple ... (1 Reply)
Hi.
I have three arrays.
@a=('AB','CD','EF');
@b=('AB,'DG',HK');
@c=('DD','TT','MM');
I want to compare the elements of the first two array and if they match then so some substition.
I tried using the if statement using the scalar value of the array but its not giving me any output.
... (7 Replies)
Hi all,
I am trying to compare two arrays in perl using the following code.
foreach $item (@arrayA){
push(@arrayC, $item) unless grep(/$item/, @arrayB); ... (1 Reply)
I have a main file with variable tokens like this:
name: File1
===========
Destination/Company=@deploy.company@
Destination/Environment=@deploy.env@
Destination/Location=@deploy.location@
Destination/Domain=@deploy.location@
MIG_GatewayAddresses=@deploy.gwaddress@
MIG_URL=@deploy.mig_url@... (1 Reply)
Hi there, i have been trying different methods and i wonder if somebody could explain to me how i would perform a comparison on two arrays for example
my @array1 = ("gary" ,"peter", "paul");
my @array2 = ("gary" ,"peter", "joe");
I have two arrays above, and i want to something like this... (5 Replies)
Hi,
I'm new to perl and i have to write a perl script that will compare to log/txt files and display the differences. Unfortunately I'm not allowed to use any complied binaries or applications like diff or comm.
So far i've across a code like this:
use strict;
use warnings;
my $list1;... (2 Replies)
What do i need to do have the below perl program load 205 million record files into the hash. It currently works on smaller files, but not working on huge files. Any idea what i need to do to modify to make it work with huge files:
#!/usr/bin/perl
$ot1=$ARGV;
$ot2=$ARGV;
open(mfileot1,... (12 Replies)
I have these two file that I am trying to compare using shell arrays. I need to find out the changed or the missing
enteries from File2. For example. The line "f nsd1" in file2 is different from file1 and the line "g nsd6" is missing
from file2.
I dont want to use "for loop" because my files... (2 Replies)
Hi everyone
I have a question for you, as I am trying to learn more about Perl and work with some weather data. I have an ascii file (shown below) that has 10 lines with different columns. What I would like is have Perl find an "anomalous" value by comparing a field with the values from the last... (2 Replies)