Yeah it's not writing to the file. I added the text "This is a test" to the labels.txt file and ran the script, which should have overwritten the contents of the file but the text I entered is still there.
Hello,
I'm trying to write to some text files but it doesn't appear to be writing to the files UNLESS I use the >> operator (append operator) when opening the file. Can anyone tell me what is going on? Below is my code which writes fine when I use the >> operator. If I remove it though...
Thanks for your help rhash. I tried your regular exression alone and it works fine however when I use your expression in my code I'm still having the same problme. Here is my code.
Any ideas on why this isn't working? I'm very perplexed.
use strict;
open(SOURCE, $ARGV[0]);
open(LABELS...
I wish it did. But it should be assigning the string V01TPRL_RLT_CLT to the $2 variable but what I'm getting when I print out this variable is TPRFL_RLT_CLT. It's missing the V01.
Hello,
I'm having a little trouble creating a regular expression to extract some information from a string. Given the string
Column : Indv Clt Id ("COMP"."V01TPRFL_RLT_CLT""INDV_CLT_ID")
I want to extract the portions
Indv Clt Id
V01TPRL_RLT_CLT
INDV_CLT_ID
At the moment my regular...
Yeah that does help. So using this technique if later I encounter the same key with the same value when it tries to add the key with the code $hash{$2}{$3} = 1; nothing wil be added because the value already exists. Is this correct? This is a nice little trick thanks!
It's working perfect now. Thanks to all of youu for all your help. Here is the final code. Feel free to make any suggestions on how to make things more efficient.
Thank you!
#use strict;
#print "$ARGV[0]";
open(MY_FILE1,$ARGV[0]);
open(OUTPUT, ">>output.txt");
while(<MY_FILE1>)
{...
That's exactly what I'm trying to do. I tried your suggestion but I'm stillonly getting one value per key/value pair in the hash. Once the ky in the hash has a value stored any subsequent value with the same key designation will not be entered into the hash becuase i think it's being caught by...
Can anyone tell me from looking at the code below why I'm only able to have one value per key in the hash despite using a hash of arrys. Below is my code. Any suggestions are appreciated. It seems from what I can tell that the code doesn't enter the part
elsif (exists $hash{$2})...
Ok here is what I have now but it still doesn't appear to be adding more than one value for a particular key.
[cod]
if($line2 =~ /^($line1)\s+CAAS.+\.([^.]+)\.([^.]+)/ )
{
$flag = 1;
if (exists $hash{$2}[$3] )
{
#do nothing
}
elsif (exists $hash{$2})
{...
The exists function you suggested looks like it will only check for the existance of the key in the hash. Will this also check for the existance of a key/value pair even when a key may have multiple values since I will be using a hash of arrays.
Hi thanks for the tips. I understand what you're saying. The reason why I did it that way was becuase I'm reading my values from a text file that might look like this.
abc keyA.12
efg keyB.17
abc keyA.12
abc KeyA.22
The string abc in this example appears twice. The...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.