New subroutine PSPP::Dict::get_var_by_name
authorJohn Darrington <john@darrington.wattle.id.au>
Thu, 25 Dec 2008 03:16:35 +0000 (12:16 +0900)
committerJohn Darrington <john@darrington.wattle.id.au>
Thu, 25 Dec 2008 03:16:35 +0000 (12:16 +0900)
perl-module/PSPP.xs
perl-module/lib/PSPP.pm

index de5cbf7b0a8eef5be89c3f08244d4a7494436c24..3b3dcceff82d275d55fd76986836f0044b30baac 100644 (file)
@@ -273,6 +273,23 @@ CODE:
  OUTPUT:
 RETVAL
 
+
+struct variable *
+pxs_get_var_by_name (dict, name)
+ struct dictionary *dict
+ const char *name
+INIT:
+ SV *errstr = get_sv("PSPP::errstr", TRUE);
+ sv_setpv (errstr, "");
+CODE:
+ struct variable *var = dict_lookup_var (dict, name);
+ if ( ! var )
+      sv_setpv (errstr, "No such variable.");
+ RETVAL = var;
+ OUTPUT:
+RETVAL
+
+
 MODULE = PSPP          PACKAGE = PSPP::Var
 
 
index a000b0115adbbd60a066787cdb6fec2f7cd19c6a..6fbae803a9b250cf3d0aa8aaccaebaaace00aba5 100644 (file)
@@ -106,6 +106,28 @@ sub get_var
     return $var;
 }
 
+=pod
+
+=head3 get_var_by_name ($name)
+
+Returns the variable from the dictionary whose name is C<name>.
+If there is no such variable, a null reference will be returned.
+
+=cut
+
+sub get_var_by_name
+{
+    my $dict = shift;
+    my $name = shift;
+    my $var = pxs_get_var_by_name ($dict, $name);
+
+    if ( ref $var ) 
+    {
+       bless ($var, "PSPP::Var");
+    }
+    return $var;
+}
+
 
 package PSPP::Fmt;