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

error in <stdin>: use of uninitialised value within %lop in concatenation or string

the following prog. i was trying but after entering the value alpha or anything generates an error that goes like : use of uninitialised value within %lop in conactenation or string at ...".please help.is there any problem with using the value obtained in scalar via <STDIN>??


Expand|Select|Wrap|Line Numbers
  1. use warnings;
  2. use strict;
  3. my $k;
  4. my %lop=(
  5. alpha=>2143,
  6. beta=>456843,
  7. gamma=>78458,
  8. delta=>6453,
  9. theta=>4658);
  10.  
  11.  
  12. $k=<STDIN>;
  13.  
  14.  
  15.  
  16. print"\n $lop{$k}";
Mar 22 '13 #1

✓ answered by sathishkumar se

Hi,

Can you try this below code.
Expand|Select|Wrap|Line Numbers
  1. use warnings;
  2. use strict;
  3. my $k;
  4. my %lop=(
  5. alpha=>2143,
  6. beta=>456843,
  7. gamma=>78458,
  8. delta=>6453,
  9. theta=>4658);
  10.  
  11.  
  12. $k=<STDIN>;
  13. chomp($k);
  14.  
  15.  
  16. print"\n $lop{$k}";

5 1638
Hi,

Can you try this below code.
Expand|Select|Wrap|Line Numbers
  1. use warnings;
  2. use strict;
  3. my $k;
  4. my %lop=(
  5. alpha=>2143,
  6. beta=>456843,
  7. gamma=>78458,
  8. delta=>6453,
  9. theta=>4658);
  10.  
  11.  
  12. $k=<STDIN>;
  13. chomp($k);
  14.  
  15.  
  16. print"\n $lop{$k}";
Mar 22 '13 #2
Rabbit
12,516 Expert Mod 8TB
I don't know perl but on line 4 you use %lop but on line 6 you use $lop. Wouldn't they have to be the same? Also you're using different brackets. Do those have to be the same?
Mar 22 '13 #3
RonB
589 Expert Mod 512MB
The explanation of hashes can get lengthy and confusing, but I'll try to keep it short and simple.
  • Hashes are unordered lists of key/value pairs.
  • % is the sigil used to denote a hash (as a whole).
  • The parens used in the hash assignment indicate list context.
  • Within the parens you have a comma separated list of key pairs which are separated by => (known as the fat comma).
  • When referring to individual pairs, you use the $ sigil instead of the % sigil and you use the { } braces around the key instead of the parens.
Mar 22 '13 #4
thanks a lot it solved the problem. but i would like to know what was the mistake in mine. also what did chomp($k) do. (i'm just starting in the basics of perl so dont know much would appreciate your explanation.).
Mar 23 '13 #5
Hi,

chomp($k);
The above code remove the newline character in the $k variable.
Mar 25 '13 #6

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

Similar topics

1
by: Sorisio, Chris | last post by:
Ladies and gentlemen, I've imported some data from a MySQL database into a Python dictionary. I'm attempting to tidy up the date fields, but I'm receiving a 'mx.DateTime.Error: cannot convert...
4
by: jt | last post by:
I'm getting a compiler error: warning C4172: returning address of local variable or temporary Here is the function that I have giving this error: I'm returning a temporary char string and its...
5
by: Johnny | last post by:
How do I assign a value in a dataset to a variable. I have the following code that's giving me an error message: char IsTaxable; IsTaxable = dsTaxData.Tables.Rows; The is_taxable datatype is...
3
by: Andy Sutorius via DotNetMonster.com | last post by:
Hi, I have a Sorted List that has 9 key/value pairs. I am trying to take one of the key/value pairs and store the value of that key into a string variable. However, the value that actually gets...
1
by: Marco Gerlach | last post by:
Hello, on one of our customers servers we get following error on first ASPX-page: An error occurred while try to load the string resources (GetModuleHandle failed with error -2147023888) ...
1
by: Kevin B. Campisi | last post by:
Hi There, I'm really stuck on this one and any help would be GREATLY appreciated. I've got an ASP.net application, that initially, gives me the following error: Login failed for user...
1
by: Stan | last post by:
I get this error when I try to access any page on the website: An error occurred while try to load the string resources (GetModuleHandle failed with error 126). At the same time here is what I...
1
by: Keith | last post by:
ADVERTISEMEN Is there any way to display quotes Themselves - within a text strin textbox1.text = "This is a "test" of inserting quotes" I want to actually use quotes within this string...
5
by: Martin Jørgensen | last post by:
Hello again, Sorry to bother but I guess my C++ book isn't very good since it obviously contains errors so the program code doesn't work with g++. However I don't understand what the problem...
14
by: Mike | last post by:
I have a gridview that has a button in the last cell of each row. I want to get the text from cell 1 for that row the button was clicked on. So if my gridview looks like this: N-12 BMW ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.