Katy has asked for the wisdom of the Perl Monks concerning the following question:
My data are transcriptions of conversations and a sample looks like this:#!/usr/local/bin/perl -w # Program to count minimal pairs by gender # Author: Katy # Last modified: December 2006 %Goodwords = ("mhm" => 1, "right" => 1, "well" => 1, "yeah" => 1, "sure" => 1, "good" => 1, "ah" => 1, "okay" => 1, "yep" => 1, "hm" => 1, "definitely" => 1, "alright" => 1, "'m'm" => 1, "oh" => 1, "my" => 1, "god" => 1, "wow" => 1, "uhuh" => 1, "exactly" => 1, "yup" => 1, "mkay" => 1, "i see" => 1, "ooh" => 1, "cool" => 1, "uh" => 1, "fine" => 1, "true" => 1, "hm'm" => 1, "hmm" => 1, "yes" => 1, "absolutely" => 1, "great" => 1, "um" => 1, "so" => 1, "mm" => 1, "weird" => 1, "ye-" => 1, "i mean" => 1, "i know" => 1, "i think so" => 1, "huh" => 1, "yay" => 1, "maybe" => 1, "eh" => 1, "obviously" => 1, "correct" => 1, "awesome" => 1, "really" => 1, "interesting" => 1,); while(<>){ if(/<strong>(S[\w\-]+)<strong>:.*Gender:\s+(Male|Female)/i){ $speakerID = $1; $speaker{$1}=$2;} if($good){ $good = 1; $minresgen{$speaker{$speakerID}}++;} $_=~ /\[(S[\w\-]+):(.*?)\]/i; use diagnostics; $minres = $2; $speakerID = $1; $minres =~ s/<.*?>//g; $minres = lc($minres); $good = 1; while($minres =~ /(\w+)/g) { unless($Goodwords{$1}) { $good = 0; last; } } print "Male:"; print $minresgen {"Male"}; print "Female:"; print $minresgen {"Female"}; }
I want to get an output that looks like: "Male:" number of times that male speakers use any of the words in the hash singularly or in combination with each other when they are within brackets. "Female:" number of times that female speakers use any of the words in the hash singularly or in combination with each other when they are within brackets. When I run the program, the only output are four warning messages that repeat for each line of text that it processes, for example, line 557:<strong>S1</strong>: Native-Speaker Status: Native speaker, American E +nglish; Academic Role: Senior Undergraduate; Gender: Male; Age: 17-23 +; Restriction: None<br> <strong>S2</strong>: Native-Speaker Status: Native speaker, American E +nglish; Academic Role: Researcher; Gender: Male; Age: 31-50; Restrict +ion: Cite<br> <strong>S3</strong>: Native-Speaker Status: Native speaker, American E +nglish; Academic Role: Junior Undergraduate; Gender: Female; Age: 17- +23; Restriction: None<br> <strong>S4</strong>: Native-Speaker Status: Native speaker, American E +nglish; Academic Role: Senior Undergraduate; Gender: Female; Age: 17- +23; Restriction: None<br> <strong>S5</strong>: Native-Speaker Status: Native speaker, American E +nglish; Academic Role: Junior Undergraduate; Gender: Female; Age: 17- +23; Restriction: None<br> <strong>SS</strong>: Native-Speaker Status: Native speaker, American E +nglish; Academic Role: Unknown; Gender: Male; Age: Unknown; Restricti +on: None<br> <p><b>S1: </b> it was presented to them by Chuck D and Public Enemy. +<font color="#ff6600"><b> [S2: </b> mhm <b> ] </b></font> and the re +st of th- Public Enemy and you know and and Chuck D's f- publicly get +s up and says you know they were with us from the beginning and, <fo +nt color="#ff6600"><b> [S2: </b> <font color="#3333ff"> mhm </font> +<b> ] </b></font> <font color="#3333ff"> all that </font> now wheth- +whether or not you know that he was reading a TelePrompTer, <font co +lor="#ff6600"><b> [S2: </b> mhm <b> ] </b></font> or or not i i thin +k is uh </p> <p><b>S2: </b> or if he was trying to make nice because of the fact t +hat Public Enemy hasn't sold records lately, <font color="#ff6600">< +b> [S1: </b> right <b> ] </b></font> and he doesn't wanna look like +some kinda old sourpuss </p>
and then there is a block of "Male:Female:Male:Female:" at the bottom of the output. When I used "use strict;" the program did not run and it sent back messages:Use of uninitialized value in hash element at C:\Documents and Settings\Owner\Desktop\minres10.pl.txt line 62, <> line 557 (#1) Use of uninitialized value in substitution (s///) at C:\Documents and Settings\Owner\Desktop\minres10.pl.txt line 67, <> line 557 (#1) Use of uninitialized value in print at C:\Documents and Settings\Owner\Desktop\minres10.pl.txt line 78, <> line 557 (#1) Use of uninitialized value in print at C:\Documents and Settings\Owner\Desktop\minres10.pl.txt line 80, <> line 557 (#1)
I am using ActivePerl 5.8.8.819 Windows (x86) AS package. Any advice on how I should change my script to make the program give me my desired output would be greatly appreciated. Thanks, KatyVariable "$speakerID" is not imported at C:\Documents and Settings\Owner\Desktop\minres10.pl.txt line 67 (#1) (F) While "use strict" in effect, you referred to a global variable that you apparently thought was imported from another module, because something else of the same name (usually a subroutine) is exported by that module. It usually means you put the wrong funny character on the front of your variable. Variable "$good" is not imported at ... line 70 (#1) Variable "%Goodwords" is not imported at ... line 72 (#1) Variable "$good" is not imported at ... line 73 (#1) Variable "%minresgen" is not imported at ... line 79 (#1) Variable "%minresgen" is not imported at ... line 81 (#1) Global symbol "$minres" requires explicit package name at ...line 66 ..."$speakerID" ...line 67 ..."$minres" ... line 68 ... "$minres" ... line 69 ... "$minres" ... line 69 ... "$good" ... line 70 ... "$minres" ... line 71 ..."%Goodwords" ... line 72 ..."$good" ... line 73 ..."%minresgen" ... line 79 ..."%minresgen" ... line 81 (F) You've said "use strict vars," which indicates that all variables must either be lexically scoped (using "my"), declared beforehand using "our," or explicitly qualified to say which package the global variable is in (using "::").
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: minimal response program code problem
by jbert (Priest) on Dec 05, 2006 at 13:57 UTC | |
|
Re: minimal response program code problem
by johngg (Canon) on Dec 05, 2006 at 14:38 UTC | |
by GrandFather (Saint) on Dec 05, 2006 at 22:31 UTC | |
by johngg (Canon) on Dec 05, 2006 at 23:33 UTC | |
|
Re: minimal response program code problem
by liverpole (Monsignor) on Dec 05, 2006 at 13:59 UTC | |
|
Re: minimal response program code problem
by zentara (Cardinal) on Dec 05, 2006 at 14:20 UTC | |
|
Re: minimal response program code problem
by Melly (Chaplain) on Dec 05, 2006 at 14:59 UTC | |
by Not_a_Number (Prior) on Dec 05, 2006 at 17:16 UTC | |
by Melly (Chaplain) on Dec 05, 2006 at 17:26 UTC | |
|
Re: minimal response program code problem
by GrandFather (Saint) on Dec 05, 2006 at 22:59 UTC |