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

Error Can't use string ("Test") as an ARRAY ref while "strict refs" in use

47
Hi guys,

I have an error "Can't use string ("Test") as an ARRAY ref while "strict refs" in use ~~~"

I am trying to add word into the database, and then it gives me this error. please help ,,

Expand|Select|Wrap|Line Numbers
  1. sub addWords {
  2.     my $self = shift;
  3.     my $wordsRef = shift;
  4.     my @words = @$wordsRef;
  5.     my $language = shift;
  6.     my $wordId;
  7.     if (!@words || !$language){
  8.         die "addWords invalid arguments.";
  9.     }
  10.     my $languageId = $language->id();
  11.     my $db = DBI->connect("dbi:SQLite:$DB_FILE","","",{RaiseError =>1, AutoCommit => 1, sqlite_unicode => 1}) or die "Unable to connect: $DBI::errstr\n"; 
  12.     foreach my $word (@words){     
  13.         $db->do("INSERT INTO Words (word, languageId) Values ( \"$word\", $languageId);") 
  14.             or print "Failed to add $word to db: $db->errstr()";        
  15.     }
  16.     $db->disconnect or warn "Disconnection failed: $DBI::errstr\n";;
  17. }
  18.  
and I add words as below, it gives me the error,,
Expand|Select|Wrap|Line Numbers
  1. $object = Database->new();
  2. $obj->addWords("Test", 1);
  3.  
Apr 21 '11 #1
1 5115
miller
1,089 Expert 1GB
You're passing 'Test' to your method

Expand|Select|Wrap|Line Numbers
  1. $obj->addWords("Test", 1);
  2.  
And then you're pulling it into a parameter which is good, but in the next line you're trying to treat it like an array reference.

Expand|Select|Wrap|Line Numbers
  1. my $wordsRef = shift;
  2. my @words = @$wordsRef;
  3.  
That is what your error means.

Do you mean to pass an array references as your second parameter, or do you only want it to be an optional array like this:

Expand|Select|Wrap|Line Numbers
  1. my @words = ref $wordsRef ? @$wordsRef : $wordsRef;
  2.  
- Miller
Apr 21 '11 #2

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

Similar topics

0
by: RitaG | last post by:
Hi. When I set "Option Strict" to On, I'm getting an error message "Option Strict On disallows implicit conversions from 'System.Object' to 'Outlook.MailItem' with the following code: Dim...
13
by: Hans | last post by:
Hello, Thanks for all your response on my question about signed/unsigned chars. The problem is this: I want to use the char array for a ArrayLookup, so I need to convert char to unsigned int....
11
by: L. Chen | last post by:
The standard says that a char* or void* pointer has the least strict alignment. But I do not know what is a strict alignment. What does that mean?
6
by: kobu.selva | last post by:
I was recently part of a little debate on the issue of whether constants and string literals are considered "data objects" in C. I'm more confused now than before. I was always under the...
10
by: universalbitmapper | last post by:
Hi, I'm trying a simple form.html that call a .html script that begins with: <?php header("This is a test"); ?> When I click on the link, I get blank page.
4
by: Shadow Lynx | last post by:
Consider this simple HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head>...
7
by: lukertin | last post by:
I have a 2-D array stored as an object, when i go to call up the array using my $testvar = @ {$self->Peptides}; it gives me the error Can't use string ("0") as an ARRAY ref while "strict...
9
by: jaynemarie | last post by:
I have a simple program that attempts to convert lines to a csv file. The way I see it it shoule output like this: Applebee's Neighborhood Grill & Bar*, 11500 Shawnee Mission Pkwy.,Shawnee, KS,...
9
by: Steve | last post by:
Hi; I've being going through some legacy code on an old JSP site I have been patching. I noticed that when I save the JSP down to my PC as an HTML file I get this javascript error in IE 6 ( ...
6
by: TC | last post by:
Hey All, I'm receiving a weird error in IE now: "The XML page cannot be displayed" This is even with the simplest of pages that I previously could view. Any ideas?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.