Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Dear perl expert, I got an odd line of string, "HASH(0x225518)|HASH(0x225440)|HASH(0x15300fc)|HASH
I got this odd line of string in my file which I used in for my output of my program. The program I wrote just uses this statement:
sub writetofile {
open(PROFAIL, ">$profail");
print PROFAIL $_[0];
close(PROFAIL);
}
where this sub, named writetofile takes 1 argument and use it as the input string to be written into the file. One last time I ran it, it went through the string exactly in my file, but one time(this time), it show me this line on top of the exact string, where the rest is still ok. This is just like a header of the file, but I haven't done anything like that. All I've just done is just the sub, then the string passed to it is just consisted of a plain user data, like name, password, and so on in line-by-line basis. It went out ok before, but not this time. If you need to see what the inputs are, I can send it to you later.
Thanks.
2 Answers
- DaveELv 41 decade agoFavorite Answer
The problem is the input. Or, it probably is. It could be in your $profail variable (because it's a global variable, so it may be getting changed elsewhere), but that's less likely. The key is that whatever you're passing got screwed up somewhere along the line. In fact, the bug probably has nothing to do with the writetofile function, or how you call it. It's probably how you're building the string that you send to it.
Somewhere along the line, you're attempting to put a hash reference into string context. A hash reference, when in string context will look something like this:
HASH(0x110595)
So it's telling you that it's a hash reference, located at memory address 0x110595. In your case, you're getting (apparently) 3 hash references, separated by pipe characters. So you're likely creating that string incorrectly, and the string that gets sent is a perfectly valid string (and getting written to the file exactly as it should be), but it's just not the string you were expecting.
With some more details, we could probably track it down a lot better.
DaveE
- martinthurnLv 61 decade ago
The argument you sent to that function has "garbage" in it.
You forgot to check whether the open succeeded.
You should use the File::Slurp module to read & write entire files.