473,325 Members | 2,805 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,325 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 5113
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.