scalar

Can you force either a scalar or array ref to be an array in Perl?

I have a perl variable $results that gets returned from a service. The value is supposed to be an array, and $results should be an array reference. However, when the array has only one item in it, $results will be set to that value, and not a referenced array that contains that one item. I want to do a foreach loop on the expected arr...

How does Perl decide to treat a scalar as a string or a number?

Consider the following code and its output: Code #!/usr/bin/perl -w use strict; use Data::Dumper; my $HOURS_PER_DAY = 24.0 * 1.0; my $BSA = 1.7 * 1.0; my $MCG_PER_MG = 1000.0 * 1.0; my $HOURS_DURATION = 20.0 * $HOURS_PER_DAY; my $dummy = $HOURS_PER_DAY * $BSA * $MCG_PER_MG * $HOURS_DURATION; print Dumper($HOURS_PER_DAY); print Dumpe...

What is the difference between the scalar and list contexts in Perl?

What is the difference between the scalar and list contexts in Perl and does this have any parallel in other languages such as Java or Javascript? ...

In SSRS 2005,must declare the scalar variable

I have a report that runs a stored proc: EXEC ra_spProjectCalendar @Month, @Year, @ProjectID ProjectID is A multi-select dropdown. When a single project is selected, it works fine. If I select multiple projects, I get the error: "Must declare scalar variable "@ProjectID" It works fine when I run it from the Data tab, however, when ...

How can I keep only the first five lines in a Perl scalar?

From any kind of scalar, what regex could I use to match the first five lines of it and discard the rest? ...

How do I create an object that returns different values in different scalar contexts?

I want to return a different value in string context and numeric context like $! does. I know I can find out whether I am in list or scalar context with wantarray, but is there any way in pure Perl to determine which scalar context I am in? I assume there is an answer in XS as well and I am willing to take that answer if there is no wa...

Scalar function in LinqToSql

In ADO.Net/SQLClient I would often do something like this: SELECT COUNT(*) FROM SomeTable WHERE SomeKey = 1234 ...and fire it using executescalar to return the value of count - for a simple check if something exists. How would I do the same using LinqToSql? ...

BLAS subroutines dgemm, dgemv and ddot doesn't work with scalars?

Hi, I have a Fortran subroutine which uses BLAS' subroutines dgemm, dgemv and ddot, which calculate matrix * matrix, matrix * vector and vector * vector. I have m * m matrices and m * 1 vectors. In some cases m=1. It seems that those subroutines doesn't work well in those cases. They doesn't give errors, but there seems to be some numer...

PHP Constants Containing Arrays?

This failed: define('DEFAULT_ROLES', array('guy', 'development team')); Apparently, constants can't hold arrays. What is the best way to get around this? define('DEFAULT_ROLES', 'guy|development team'); //... $default = split(DEFAULT_ROLES, '|'); This seems like unnecessary effort. ...

Hibernate Criteria contains-in on an association to a table

Good day, I have a Hibernate mapping that looks something like this: <class name="MyEntity"> <set name="scalarSet" table="(select fk, scalar_value from other_table)"> <key column="fk"/> <property column="scalar_value" type="long"/> </set> </class Given this, how do I query such that a value of MyEntity.scalarSet (which is...

VB.NET - SQLCommand.ExecScalar() throws unreferenced exception on Return?

I'm calling Sqlcommand.ExecScalar() - stepping through the stored proc works fine, right under RETURN @RecordNum @RecordNum correctly contains a bigint, as scoped. When I step into the RETURN.. I get an exception thrown, that visual studio does not seem to be able to capture. The stored procedure works fine when executed directly, a...

How can I call methods on Perl scalars?

I saw some code that called methods on scalars (numbers), something like: print 42->is_odd What do you have to overload so that you can achieve this sort of "functionality" in your code? ...

How should I use Perl's scalar range operator?

What is the scalar ".." operator typical usage? Is it only selecting blocks of text? Interesting example by myself: sub get_next { print scalar($$..!$$), "\n"; } get_next for 1 .. 5; # prints numbers from 1 to 5 get_next for 1 .. 5; # prints numbers from 6 to 10 ...

What is Perl's $; variable for?

Does any 1 have any idea what is $; (first split function argument) in the following code snippet: local(@a) = (); local($i) = 0; for ($i = 0; $i < $d; $i++) { @a = split($;, @b[$i]); $c = @a[0]; } The scalar is not found any where in the script other than in the for loop. Any help is app...

Hibernate Criteria API and Scalar Subqueries

Hi, I want to translate a HQL query to Criteria API but I don't know if it's possible to write the same thing with Criteria. The HQL looks like this: select distinct new DataTransferObject(property1, property2, ..., (select NVL(property3, null) from Table1 where property3 in elements(...) and ... ), property4, ..., (select .....), ...)...

C - only scalar operations?

Reading on Wikipedia: "The terms high-level and low-level are inherently relative. Some decades ago, the C language, and similar languages, was most often considered "high-level", as it supported concepts such as expression evaluation, parameterised recursive functions, and data types and structures, while assembly language was consi...

How do I define an implicit typecast from my class to a scalar?

I have the following code, which uses a Unicode string class from a library that I'm writing: #include <cstdio> #include "ucpp" main() { ustring a = "test"; ustring b = "ing"; ustring c = "- -"; ustring d; d = "cafe\xcc\x81"; printf("%s\n", (a + b + c[1] + d).encode()); } The encode method of the ustring class instances co...

OpenCV multiply scalar and a Matrix

Hi, I am trying to find the easiest way to add, subtract a scalar value with a opencv 2.0 cv::Mat class. Most of the existing function allows only matrix-matrix and matrix-scalar operations. I am looking for a scalar-matrix operations. I am doing it currently by creating a temporary matrix with the same scalar value and doing require...

Converting a constantly changing scalar value to a changing interval or frequency

Although I'm coding in Objective C, this is more of a general programming question. What is the best way to convert a constantly changing scalar value to a changing interval or frequency? Right now every time the scalar value changes I am destroying the NSInterval ie [self.myTimer invalidate]; self.myTimer = nil; and creating...

returning a lazily-computed scalar, in perl

I'm trying to add some functionality to our code base by using tied scalars. We have a function which is specified to return scalars. I thought I could add some features to the system by tie-ing these scalars before returning them, but it looks like the FETCH method is called just before the return, which results in an untied scalar bei...