G'day Kati,
Welcome to the Monastery.
"Use of uninitialized value in concatenation (.) or string at sequence_replacement.pl line 56, <TWO> line ..."
Here's line 56:
if(/>(.*)/){if(defined $list{$1}){print $_. "\n" . $hash1{$list{$1}} . + "\n"; $x = 1}else{$x = 0}}
Here's the only concatenation occurring on that line:
print $_. "\n" . $hash1{$list{$1}} . "\n";
That's the problem identified. At this point, I'll leave the solution for you to determine (a good learning exercise). If you really can't fix this yourself, feel free to ask another question but ensure you tell us what you've tried. Adding print statements to see the value of $list{$1} on each iteration would probably be a good start; however, see my comments on laying out your code (below) before doing so.
"I'm really new in this field, ..."
Here's a few tips and pointers:
Writing code like
if(/>(.*)/){if(defined $list{$1}){print $_. "\n" . $hash1{$list{$1}} . + "\n"; $x = 1}else{$x = 0}}
is a recipe for disaster. It's hard to read; hard to maintain; hard to troubleshoot. Take a look at "perlstyle: The Perl Style Guide"; choose a style that you're happy with and use it consistently. Here's how I would have laid out that code. Note: it's exactly the same code you wrote — bugs and all!
if (/>(.*)/) { if (defined $list{$1}) { print $_ . "\n" . $hash1{$list{$1}} . "\n"; $x = 1; } else { $x = 0; } }
That's now much easier to read: you can see the logic at a glance. Accordingly, it's also easier to maintain and troubleshoot.
The print function takes a list. There's no reason to perform three separate concatenation operations to generate an argument for print — just provide a list:
print $_, "\n", $hash1{$list{$1}}, "\n";
You'd probably benefit from reading "perlintro: Perl Introduction for Beginners". While it's very basic in itself, each section contains links to more detailed information and advanced topics.
Perl has lots of documentation, all of which you can find linked from the online "perl manpage". Take some time seeing what's there. The first three sections (Overview, Tutorials and Reference Manual) probably contain pretty much everything you might need while you're learning.
A word of caution: "perlfunc: Perl Built-in Functions" documents all functions in a single web page and is enormous. You'll rarely, if ever, need this. Instead, use the "Perl Functions A-Z" index. [There's a link to that on the online "perl manpage": left sidebar; under "Reference"; labelled "Functions"].
"I faced with the following error ..."
Actually, that's a warning, not an error. You used the strict and warnings pragmata: this is very good — keep doing it. Use of the latter is why you got all those warnings. By default, those types of messages are restricted to just one line; however, you can find a much more verbose version (of both warning and error messages) from "perldiag: Perl Diagnostic Messages". While you're learning, you can get the verbose form automatically with the diagnostics pragma. This can cause a lot of clutter in your output and, eventually, you won't want it. Also, don't use this in any production code: it's only intended as a developer tool.
Finally, I did see your original post with just the output and a variety of requests to see the code. Now that you've supplied the code, tracking down the source of the problem was easy: had you supplied the code in the first place, you could have had an answer hours ago. I'm not trying to tell you off — this was your first post and you didn't know. For future reference, following the guidelines in "How do I post a question effectively?" will get you answers instead of requests for more information.
-- Ken
In reply to Re: Getting (famous) error during running perl script
by kcott
in thread Getting (famous) error during running perl script
by Kati
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |